0.0.33 • Published 11 months ago

qustar-better-sqlite3 v0.0.33

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

qustar-better-sqlite3

SQLite support for qustar via better-sqlite3 package.

Installation

To start using better-sqlite3 with qustar you need to install the following packages:

npm install qustar qustar-better-sqlite3 better-sqlite3

Usage

Here is a minimal example:

import {Q} from 'qustar';
import {BetterSqlite3Connector} from 'qustar-better-sqlite3';

// create a connector for in-memory SQLite database
const connector = new BetterSqlite3Connector(':memory:');

// construct a query
const query = Q.table({
  name: 'users',
  schema: {
    id: Q.i32(),
  },
});

// run the query using the connector
const users = await query.fetch(connector);

// use the result
console.log(users);

// close the connector
await connector.close();

You can also create BetterSqlite3Connector by passing an instance of better-sqlite3 database:

import Database from 'better-sqlite3';

const db = new Database('/path/to/db.sqlite', {
  readonly: true,
  fileMustExist: false,
});

const connector = new BetterSqlite3Connector(db);

But usually it's more convenient to pass database options directly to the connector:

import {BetterSqlite3Connector} from 'qustar-better-sqlite3';

// connector will pass the options to better-sqlite3
const connector = new BetterSqlite3Connector('/path/to/db.sqlite', {
  readonly: true,
  fileMustExist: false,
});

You can run raw SQL using a connector:

// execute a statement
await connector.execute('INSERT INTO users VALUES (42);');

// run a query
await connector.query('SELECT 42 as meaning');

// run a parametrized query
await connector.query({
  sql: 'SELECT id FROM users WHERE id = ?',
  args: [42],
});

License

MIT License, see LICENSE.

0.0.33

11 months ago

0.0.32

11 months ago

0.0.31

11 months ago

0.0.30

11 months ago

0.0.29

11 months ago

0.0.28

11 months ago

0.0.27

11 months ago

0.0.26

11 months ago

0.0.25

11 months ago

0.0.24

11 months ago

0.0.23

11 months ago

0.0.22

11 months ago

0.0.21

11 months ago

0.0.20

11 months ago

0.0.19

11 months ago

0.0.18

11 months ago

0.0.17

11 months ago

0.0.16

11 months ago

0.0.15

11 months ago

0.0.14

11 months ago

0.0.13

11 months ago

0.0.12

11 months ago

0.0.11

11 months ago

0.0.10

11 months ago

0.0.9

12 months ago

0.0.8

12 months ago

0.0.7

12 months ago

0.0.6

12 months ago

0.0.5

12 months ago

0.0.4

12 months ago

0.0.3

12 months ago

0.0.2

12 months ago