Website Structure
This commit is contained in:
parent
62812f2090
commit
71f0676a62
22365 changed files with 4265753 additions and 791 deletions
54
Frontend-Learner/node_modules/db0/dist/connectors/node-sqlite.mjs
generated
vendored
Normal file
54
Frontend-Learner/node_modules/db0/dist/connectors/node-sqlite.mjs
generated
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import { resolve, dirname } from "node:path";
|
||||
import { mkdirSync } from "node:fs";
|
||||
import { BoundableStatement } from "./_internal/statement.mjs";
|
||||
export default function nodeSqlite3Connector(opts) {
|
||||
let _db;
|
||||
const getDB = () => {
|
||||
if (_db) {
|
||||
return _db;
|
||||
}
|
||||
const nodeSqlite = globalThis.process?.getBuiltinModule?.("node:sqlite");
|
||||
if (!nodeSqlite) {
|
||||
throw new Error("`node:sqlite` module is not available. Please ensure you are running in Node.js >= 22.5 or Deno >= 2.2.");
|
||||
}
|
||||
if (opts.name === ":memory:") {
|
||||
_db = new nodeSqlite.DatabaseSync(":memory:");
|
||||
return _db;
|
||||
}
|
||||
const filePath = resolve(opts.cwd || ".", opts.path || `.data/${opts.name || "db"}.sqlite`);
|
||||
mkdirSync(dirname(filePath), { recursive: true });
|
||||
_db = new nodeSqlite.DatabaseSync(filePath);
|
||||
return _db;
|
||||
};
|
||||
return {
|
||||
name: "node-sqlite",
|
||||
dialect: "sqlite",
|
||||
getInstance: () => getDB(),
|
||||
exec(sql) {
|
||||
getDB().exec(sql);
|
||||
return { success: true };
|
||||
},
|
||||
prepare: (sql) => new StatementWrapper(() => getDB().prepare(sql)),
|
||||
dispose: () => {
|
||||
_db?.close?.();
|
||||
_db = undefined;
|
||||
}
|
||||
};
|
||||
}
|
||||
class StatementWrapper extends BoundableStatement {
|
||||
async all(...params) {
|
||||
const raws = this._statement().all(...params);
|
||||
return raws;
|
||||
}
|
||||
async run(...params) {
|
||||
const res = this._statement().run(...params);
|
||||
return {
|
||||
success: true,
|
||||
...res
|
||||
};
|
||||
}
|
||||
async get(...params) {
|
||||
const raw = this._statement().get(...params);
|
||||
return raw;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue