diff --git a/benchmark/drivers.js b/benchmark/drivers.js index d2a43d53f..01d41482c 100644 --- a/benchmark/drivers.js +++ b/benchmark/drivers.js @@ -19,3 +19,12 @@ module.exports = new Map([ return db; }], ]); + +const moduleExists = (m) => { try { return require.resolve(m); } catch (e) {} }; +if (moduleExists('node:sqlite')) { + module.exports.set('node:sqlite', async (filename, pragma) => { + const db = new (require('node:sqlite').DatabaseSync)(filename, {open: true}); + for (const str of pragma) db.exec(`PRAGMA ${str}`); + return db; + }); +} diff --git a/benchmark/index.js b/benchmark/index.js index 75028b64e..3b8068fd5 100755 --- a/benchmark/index.js +++ b/benchmark/index.js @@ -69,7 +69,7 @@ for (const trial of trials) { const ctx = createContext(trial, driver); process.stdout.write(`${driver} (running...)\n`); try { - const result = execFileSync('node', ['./benchmark.js', ctx], { stdio: 'pipe', encoding: 'utf8' }); + const result = execFileSync('node', [...process.execArgv, './benchmark.js', ctx], { stdio: 'pipe', encoding: 'utf8' }); console.log(erase() + `${driverName} x ${result}`); } catch (err) { console.log(erase() + clc.red(`${driverName} ERROR (probably out of memory)`)); diff --git a/benchmark/types/insert.js b/benchmark/types/insert.js index 2b68119ed..21cdc0e4f 100644 --- a/benchmark/types/insert.js +++ b/benchmark/types/insert.js @@ -14,3 +14,14 @@ exports['node-sqlite3'] = async (db, { table, columns }) => { .map(([k, v]) => ({ ['@' + k]: v }))); return () => db.run(sql, row); }; + +exports['node:sqlite'] = (db, { table, columns }) => { + const sql = `INSERT INTO ${table} (${columns.join(', ')}) VALUES (${columns.map(x => '@' + x).join(', ')})`; + const row = Object.assign({}, ...Object.entries(db.prepare(`SELECT * FROM ${table} LIMIT 1`).get()) + .filter(([k]) => columns.includes(k)) + .map(([k, v]) => ({ ['@' + k]: v }))); + return () => { + const stmt = db.prepare(sql); + return stmt.run(row); + } +}; \ No newline at end of file diff --git a/benchmark/types/select-all.js b/benchmark/types/select-all.js index 2d6e1ede1..ad63a20f5 100644 --- a/benchmark/types/select-all.js +++ b/benchmark/types/select-all.js @@ -12,3 +12,12 @@ exports['node-sqlite3'] = async (db, { table, columns, count }) => { let rowid = -100; return () => db.all(sql, (rowid += 100) % count + 1); }; + +exports['node:sqlite'] = (db, { table, columns, count }) => { + const sql = `SELECT ${columns.join(', ')} FROM ${table} WHERE rowid >= ? LIMIT 100`; + let rowid = -100; + return () => { + const stmt = db.prepare(sql); + return stmt.all((rowid += 100) % count + 1); + } +}; \ No newline at end of file diff --git a/benchmark/types/select-iterate.js b/benchmark/types/select-iterate.js index fe71a35d9..3eb70c3c7 100644 --- a/benchmark/types/select-iterate.js +++ b/benchmark/types/select-iterate.js @@ -21,3 +21,19 @@ exports['node-sqlite3'] = async (db, { table, columns, count }) => { })(); }; }; + +exports['node:sqlite'] = (db, { table, columns, count }) => { + const sql = `SELECT ${columns.join(', ')} FROM ${table} WHERE rowid >= ? LIMIT 100`; + let rowid = -100; + + if (!("iterate" in require("node:sqlite").StatementSync.prototype)) { + // Error: StatementSync.iterate is not a function (added in Node v23.4.0+) + return () => {}; + } + + return () => { + // Error: statement has been finalized + // for (const row of db.prepare(sql).iterate((rowid += 100) % count + 1)) {} + return () => {}; + }; +}; \ No newline at end of file diff --git a/benchmark/types/select.js b/benchmark/types/select.js index 1c457c5eb..0d0f8369d 100644 --- a/benchmark/types/select.js +++ b/benchmark/types/select.js @@ -12,3 +12,12 @@ exports['node-sqlite3'] = async (db, { table, columns, count }) => { let rowid = -1; return () => db.get(sql, ++rowid % count + 1); }; + +exports['node:sqlite'] = (db, { table, columns, count }) => { + const sql = `SELECT ${columns.join(', ')} FROM ${table} WHERE rowid = ?`; + let rowid = -1; + return () => { + const stmt = db.prepare(sql); + return stmt.get(++rowid % count + 1); + } +}; \ No newline at end of file diff --git a/benchmark/types/transaction.js b/benchmark/types/transaction.js index 54fb482e0..974170968 100644 --- a/benchmark/types/transaction.js +++ b/benchmark/types/transaction.js @@ -38,3 +38,16 @@ exports['node-sqlite3'] = async (db, { table, columns, driver, pragma }) => { } }); }; + +exports['node:sqlite'] = (db, { table, columns }) => { + const sql = `INSERT INTO ${table} (${columns.join(', ')}) VALUES (${columns.map(x => '@' + x).join(', ')})`; + const row = Object.assign({}, ...Object.entries(db.prepare(`SELECT * FROM ${table} LIMIT 1`).get()) + .filter(([k]) => columns.includes(k)) + .map(([k, v]) => ({ ['@' + k]: v }))); + return () => { + const stmt = db.prepare(sql); + db.exec(`BEGIN`); + for (let i = 0; i < 100; ++i) stmt.run(row); + db.exec(`COMMIT`); + } +}; \ No newline at end of file