LogoPear Docs
ReferencesBareModules

bare-sqlite

Reference for bare-sqlite: synchronous SQLite bindings for Bare, with a DatabaseSync/Statement API close to Node.js node:sqlite.

bare-sqlite provides SQLite bindings for Bare. The API mirrors Node.js's node:sqlite (DatabaseSync + prepared statements). It's a native addon.

npm i bare-sqlite

Usage

const { DatabaseSync } = require('bare-sqlite')

const db = new DatabaseSync(':memory:')

db.exec(`
  CREATE TABLE books (id INTEGER PRIMARY KEY, title TEXT);
  INSERT INTO books (title) VALUES ('Dune'), ('Foundation');
`)

for (const row of db.prepare('SELECT id, title FROM books').iterate()) {
  console.log(row)
}

db.close()

API

DatabaseSync

const db = new DatabaseSync(location[, options])

Open (or create) a database at location (a file path or ':memory:').

db.isOpen · db.open() · db.close()

Connection state and lifecycle.

db.exec(sql)

Execute one or more statements without returning rows.

const stmt = db.prepare(sql)

Compile a SQL statement into a reusable Statement.

db.enableLoadExtension(allow) · db.loadExtension(path[, entryPoint])

Opt into and load SQLite extensions.

const sql = db.createTagStore([maxSize])

Create a tagged-template SQL helper bound to this database.

Statement

const rows = stmt.all(...params) · stmt.values(...params) · const row = stmt.get(...params)

Run a query and return all rows, raw value arrays, or the first row.

const result = stmt.run(...params)

Execute a write and return the change count and last insert row id.

for (const row of stmt.iterate(...params)) { ... }

Iterate rows lazily.

stmt.columns() · stmt.sourceSQL · stmt.expandedSQL

Column metadata and the statement's source/expanded SQL.

stmt.setReadBigInts(enabled) · stmt.setAllowBareNamedParameters(allow) · stmt.setAllowUnknownNamedParameters(allow)

Tune integer and named-parameter handling. Parameters bind positionally (?) or by name; see the repository README for the binding rules.

See also

On this page