feat(napi): Provide a new createIndex API in the napi SDK. (#857)

This commit is contained in:
Lei Xu
2024-01-24 17:27:46 -08:00
committed by Weston Pace
parent 7d82e56f76
commit db4a979278
16 changed files with 518 additions and 22 deletions

View File

@@ -12,12 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::query::Query;
use arrow_ipc::writer::FileWriter;
use napi::bindgen_prelude::*;
use napi_derive::napi;
use vectordb::{ipc::ipc_file_to_batches, table::TableRef};
use crate::index::IndexBuilder;
use crate::query::Query;
#[napi]
pub struct Table {
pub(crate) table: TableRef,
@@ -43,7 +45,7 @@ impl Table {
}
#[napi]
pub async unsafe fn add(&mut self, buf: Buffer) -> napi::Result<()> {
pub async fn add(&self, buf: Buffer) -> napi::Result<()> {
let batches = ipc_file_to_batches(buf.to_vec())
.map_err(|e| napi::Error::from_reason(format!("Failed to read IPC file: {}", e)))?;
self.table.add(Box::new(batches), None).await.map_err(|e| {
@@ -65,7 +67,7 @@ impl Table {
}
#[napi]
pub async unsafe fn delete(&mut self, predicate: String) -> napi::Result<()> {
pub async fn delete(&self, predicate: String) -> napi::Result<()> {
self.table.delete(&predicate).await.map_err(|e| {
napi::Error::from_reason(format!(
"Failed to delete rows in table {}: predicate={}",
@@ -74,6 +76,11 @@ impl Table {
})
}
#[napi]
pub fn create_index(&self) -> IndexBuilder {
IndexBuilder::new(self.table.as_ref())
}
#[napi]
pub fn query(&self) -> Query {
Query::new(self)