Jelajahi Sumber

add query api

czhen 3 tahun lalu
induk
melakukan
45440c68a8

+ 11 - 0
express/src/collections/collections.service.ts

@@ -108,6 +108,17 @@ export class CollectionsService {
     return res;
   }
 
+  async query(data: {
+    collection_name: string;
+    expr: string;
+    partitions_names?: string[];
+    output_fields?: string[];
+  }) {
+    const res = await this.dataManager.query(data);
+    throwErrorFromSDK(res.status);
+    return res;
+  }
+
   /**
    * We do not throw error for this.
    * Because if collection dont have index, it will throw error.

+ 13 - 0
express/src/collections/index.ts

@@ -126,6 +126,19 @@ router.post("/:name/search", async (req, res, next) => {
     next(error);
   }
 });
+router.post("/:name/query", async (req, res, next) => {
+  const name = req.params?.name;
+  const data = req.body;
+  try {
+    const result = await collectionsService.query({
+      collection_name: name,
+      ...data,
+    });
+    res.send(result);
+  } catch (error) {
+    next(error);
+  }
+});
 
 router.post("/:name/alias", async (req, res, next) => {
   const name = req.params?.name;