The database instance to enhance
The same instance with .pragma(), .transaction(), and
.pluck() / .raw() / .expand() (on prepared statements) guaranteed
import { DatabaseSync, enhance } from '@photostructure/sqlite';
const db = enhance(new DatabaseSync(':memory:'));
// better-sqlite3-style pragma
db.pragma('journal_mode = wal');
// better-sqlite3-style transactions
const insertMany = db.transaction((items) => {
for (const item of items) insert.run(item);
});
// better-sqlite3-style pluck
const count = db.prepare("SELECT COUNT(*) FROM users").pluck().get();
const names = db.prepare("SELECT name FROM users").pluck().all();
Ensures that
.pragma(),.transaction(), and statement modes (.pluck(),.raw(),.expand()) are available on the given database.This function can enhance:
node:sqliteDatabaseSync instances (adds the methods)@photostructure/sqliteDatabaseSync instances (adds the methods)exec(),prepare(), andisTransactionThe enhancement is done by adding methods directly to the instance, not the prototype, so it won't affect other instances or the original class.