SQLite

new DatabaseSync()

Creates a database connection. Choose a controlled path and avoid exposing a user-supplied filename as a database selector. The synchronous API can block the event loop; the 22.16.0 module is experimental. This fixture uses an isolated in-memory database. Tested on Node.js 22.16.0. Example output (one line per entry): ["true 5"].

Formal Syntax & Structure

nodejs syntaxnodejs
new DatabaseSync(path[, options])

Parameters & Attributes

NameTypeDescription
pathstring | Buffer | URLDatabase location.
optionsobjectConnection options.

Return Value

DatabaseSync

Connection object.

Working Example

Example Snippetnodejs
import { DatabaseSync } from 'node:sqlite';const db = new DatabaseSync(':memory:');try {    console.log(db.isOpen, db.prepare('SELECT 2+3 AS n').get().n);}finally {    db.close();}
Node.js Reference