@intrnl/sqlite-system
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

sqlite-system

Painless Node.js wrapper for SQLite, works by spawning a sqlite3 shell process and communicating to it, removing the need for a native addon.

Requires at least SQLite v3.33.0, only tested with v3.35.4+ on Linux.

  • .print command (v3.7.15)
  • JSON output mode (v3.33.0)

Usage

import { Client } from '@intrnl/sqlite-system';

// File path relative to current working directory,
// default is in-memory database.
let db = new Client({ filename: './data.db' });

await db.open();

let result = await db.run('SELECT * FROM users');
// [
//   { id: 1, name: 'John' },
//   { id: 2, name: 'Bill' }
// ]

await db.close();

SQL tagged templates and escaping

Due to the use of sqlite3, prepared statements are unavailable, but the library provides built-in escaping utilities.

import { sql } from '@intrnl/sqlite-system';

// Escape values
sql`INSERT INTO users (name) VALUES (${'foobar'})`;

// Interpolate raw SQL
let table = sql.raw('scores');
sql`INSERT INTO ${table} (name, score) VALUES (${'foobar'}, ${123})`;

// Join queries
sql`SELECT * FROM books ${hasId ? sql`WHERE ids IN (${sql.join(ids)})` : sql.empty}`;

License

sqlite-system © intrnl
Licensed under MIT

Dependencies (0)

    Dev Dependencies (3)

    Package Sidebar

    Install

    npm i @intrnl/sqlite-system

    Weekly Downloads

    1

    Version

    0.2.0

    License

    MIT

    Unpacked Size

    10.1 kB

    Total Files

    11

    Last publish

    Collaborators

    • intrnl