db0
Version:
Lightweight SQL Connector
45 lines (44 loc) • 949 B
JavaScript
import { BoundableStatement } from "../_internal/statement.mjs";
export default function libSqlCoreConnector(opts) {
const query = (sql) => opts.getClient().execute(sql);
return {
name: opts.name || "libsql-core",
dialect: "libsql",
getInstance: async () => opts.getClient(),
exec: (sql) => query(sql),
prepare: (sql) => new StatementWrapper(sql, query),
dispose: () => {
opts.getClient()?.close?.();
}
};
}
class StatementWrapper extends BoundableStatement {
constructor(sql, query) {
super();
this.
this.
}
async all(...params) {
const res = await this.
sql: this.
args: params
});
return res.rows;
}
async run(...params) {
const res = await this.
sql: this.
args: params
});
return { ...res };
}
async get(...params) {
const res = await this.
sql: this.
args: params
});
return res.rows[0];
}
}