feat(nodejs): expose offset (#1620)

PR closes #1555
This commit is contained in:
Gagan Bhullar
2024-09-09 12:54:40 -06:00
committed by GitHub
parent 2a6586d6fb
commit bcc19665ce
3 changed files with 19 additions and 0 deletions

View File

@@ -396,6 +396,10 @@ describe("When creating an index", () => {
.toArrow();
expect(rst2.numRows).toBe(2);
expect(rst.toString()).toEqual(rst2.toString());
// test offset
rst = await tbl.query().limit(2).offset(1).nearestTo(queryVec).toArrow();
expect(rst.numRows).toBe(1);
});
it("should allow parameters to be specified", async () => {

View File

@@ -234,6 +234,11 @@ export class QueryBase<NativeQueryType extends NativeQuery | NativeVectorQuery>
return this;
}
offset(offset: number): this {
this.doCall((inner: NativeQueryType) => inner.offset(offset));
return this;
}
protected nativeExecute(
options?: Partial<QueryExecutionOptions>,
): Promise<NativeBatchIterator> {

View File

@@ -64,6 +64,11 @@ impl Query {
self.inner = self.inner.clone().limit(limit as usize);
}
#[napi]
pub fn offset(&mut self, offset: u32) {
self.inner = self.inner.clone().offset(offset as usize);
}
#[napi]
pub fn nearest_to(&mut self, vector: Float32Array) -> Result<VectorQuery> {
let inner = self
@@ -166,6 +171,11 @@ impl VectorQuery {
self.inner = self.inner.clone().limit(limit as usize);
}
#[napi]
pub fn offset(&mut self, offset: u32) {
self.inner = self.inner.clone().offset(offset as usize);
}
#[napi(catch_unwind)]
pub async fn execute(
&self,