mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-08-03 01:32:17 +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");
|
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 connect = async (path) => {
|
||||||
const db = new Database(path);
|
const db = new Database(path);
|
||||||
return [db];
|
return [db];
|
||||||
|
|
|
@ -109,13 +109,18 @@ impl Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[napi]
|
#[napi]
|
||||||
pub fn load_extension(&self) {
|
pub fn load_extension(&self, path: String) -> napi::Result<()> {
|
||||||
todo!()
|
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]
|
#[napi]
|
||||||
pub fn exec(&self) {
|
pub fn exec(&self, sql: String) -> napi::Result<()> {
|
||||||
todo!()
|
self.conn.query(sql).map_err(into_napi_error)?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[napi]
|
#[napi]
|
||||||
|
@ -133,7 +138,8 @@ impl Database {
|
||||||
let pragma_name = pragma
|
let pragma_name = pragma
|
||||||
.split("PRAGMA")
|
.split("PRAGMA")
|
||||||
.find(|s| !s.trim().is_empty())
|
.find(|s| !s.trim().is_empty())
|
||||||
.unwrap();
|
.unwrap()
|
||||||
|
.trim();
|
||||||
|
|
||||||
let mut results = env.create_empty_array()?;
|
let mut results = env.create_empty_array()?;
|
||||||
|
|
||||||
|
|
|
@ -112,8 +112,8 @@ class Database {
|
||||||
throw new Error("not implemented");
|
throw new Error("not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
loadExtension(...args) {
|
loadExtension(path) {
|
||||||
throw new Error("not implemented");
|
this.db.loadExtension(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
maxWriteReplicationIndex() {
|
maxWriteReplicationIndex() {
|
||||||
|
@ -126,11 +126,7 @@ class Database {
|
||||||
* @param {string} sql - The SQL statement string to execute.
|
* @param {string} sql - The SQL statement string to execute.
|
||||||
*/
|
*/
|
||||||
exec(sql) {
|
exec(sql) {
|
||||||
try {
|
this.db.exec(sql);
|
||||||
this.db.exec(sql);
|
|
||||||
} catch (err) {
|
|
||||||
throw convertError(err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue