feat(nodejs): make tbl.search chainable (#1421)

so this was annoying me when writing the docs. 

for a `search` query, one needed to chain `async` calls.

```ts
const res = await (await tbl.search("greetings")).toArray()
```

now the promise will be deferred until the query is collected, leading
to a more functional API

```ts
const res = await tbl.search("greetings").toArray()
```
This commit is contained in:
Cory Grinstead
2024-07-02 14:31:57 -05:00
committed by GitHub
parent 46c6ff889d
commit b8ccea9f71
6 changed files with 112 additions and 57 deletions

View File

@@ -706,10 +706,10 @@ describe("table.search", () => {
const data = [{ text: "hello world" }, { text: "goodbye world" }];
const table = await db.createTable("test", data, { schema });
const results = await table.search("greetings").then((r) => r.toArray());
const results = await table.search("greetings").toArray();
expect(results[0].text).toBe(data[0].text);
const results2 = await table.search("farewell").then((r) => r.toArray());
const results2 = await table.search("farewell").toArray();
expect(results2[0].text).toBe(data[1].text);
});
@@ -721,7 +721,7 @@ describe("table.search", () => {
];
const table = await db.createTable("test", data);
expect(table.search("hello")).rejects.toThrow(
expect(table.search("hello").toArray()).rejects.toThrow(
"No embedding functions are defined in the table",
);
});