mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-07-24 04:45:00 +00:00
bindings/js: Add extension loading
This commit is contained in:
parent
dd029b3d37
commit
7dc69c9c39
3 changed files with 23 additions and 12 deletions
|
@ -71,6 +71,15 @@ test("Test pragma", async (t) => {
|
|||
t.deepEqual(typeof db.pragma("cache_size", { simple: true }), "number");
|
||||
});
|
||||
|
||||
test("test extension loading", async (t) => {
|
||||
const [db] = await connect(":memory:");
|
||||
db.loadExtension("../../target/debug/liblimbo_crypto.so");
|
||||
t.deepEqual(
|
||||
typeof db.prepare("select crypto_sha256('asdf')").get(),
|
||||
"object",
|
||||
);
|
||||
});
|
||||
|
||||
const connect = async (path) => {
|
||||
const db = new Database(path);
|
||||
return [db];
|
||||
|
|
|
@ -109,13 +109,18 @@ impl Database {
|
|||
}
|
||||
|
||||
#[napi]
|
||||
pub fn load_extension(&self) {
|
||||
todo!()
|
||||
pub fn load_extension(&self, path: String) -> napi::Result<()> {
|
||||
let ext_path = limbo_core::resolve_ext_path(path.as_str()).map_err(into_napi_error)?;
|
||||
self.conn
|
||||
.load_extension(ext_path)
|
||||
.map_err(into_napi_error)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[napi]
|
||||
pub fn exec(&self) {
|
||||
todo!()
|
||||
pub fn exec(&self, sql: String) -> napi::Result<()> {
|
||||
self.conn.query(sql).map_err(into_napi_error)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[napi]
|
||||
|
@ -133,7 +138,8 @@ impl Database {
|
|||
let pragma_name = pragma
|
||||
.split("PRAGMA")
|
||||
.find(|s| !s.trim().is_empty())
|
||||
.unwrap();
|
||||
.unwrap()
|
||||
.trim();
|
||||
|
||||
let mut results = env.create_empty_array()?;
|
||||
|
||||
|
|
|
@ -112,8 +112,8 @@ class Database {
|
|||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
loadExtension(...args) {
|
||||
throw new Error("not implemented");
|
||||
loadExtension(path) {
|
||||
this.db.loadExtension(path);
|
||||
}
|
||||
|
||||
maxWriteReplicationIndex() {
|
||||
|
@ -126,11 +126,7 @@ class Database {
|
|||
* @param {string} sql - The SQL statement string to execute.
|
||||
*/
|
||||
exec(sql) {
|
||||
try {
|
||||
this.db.exec(sql);
|
||||
} catch (err) {
|
||||
throw convertError(err);
|
||||
}
|
||||
this.db.exec(sql);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue