penambahan web socket
This commit is contained in:
No files matched your search
Generated
Vendored
+42
@@ -0,0 +1,42 @@
|
||||
import { resolve, dirname } from "node:path";
|
||||
import { mkdirSync } from "node:fs";
|
||||
import Database from "better-sqlite3";
|
||||
import { BoundableStatement } from "./_internal/statement.mjs";
|
||||
export default function sqliteConnector(opts) {
|
||||
let _db;
|
||||
const getDB = () => {
|
||||
if (_db) {
|
||||
return _db;
|
||||
}
|
||||
if (opts.name === ":memory:") {
|
||||
_db = new Database(":memory:");
|
||||
return _db;
|
||||
}
|
||||
const filePath = resolve(
|
||||
opts.cwd || ".",
|
||||
opts.path || `.data/${opts.name || "db"}.sqlite3`
|
||||
);
|
||||
mkdirSync(dirname(filePath), { recursive: true });
|
||||
_db = new Database(filePath);
|
||||
return _db;
|
||||
};
|
||||
return {
|
||||
name: "sqlite",
|
||||
dialect: "sqlite",
|
||||
getInstance: () => getDB(),
|
||||
exec: (sql) => getDB().exec(sql),
|
||||
prepare: (sql) => new StatementWrapper(() => getDB().prepare(sql))
|
||||
};
|
||||
}
|
||||
class StatementWrapper extends BoundableStatement {
|
||||
async all(...params) {
|
||||
return this._statement().all(...params);
|
||||
}
|
||||
async run(...params) {
|
||||
const res = this._statement().run(...params);
|
||||
return { success: res.changes > 0, ...res };
|
||||
}
|
||||
async get(...params) {
|
||||
return this._statement().get(...params);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user