This package builds on sqlite3. It provides a promise-based API for interacting with your sqlite database.
Install this package with npm:
npm i sqlite-database
import { SqliteDatabase } from 'sqlite-database';
const db = new SqliteDatabase('path/to/db');
const users = await db.all('SELECT id, name FROM Users');
Add typings to SELECT
queries:
const users = await db.all<{ id: number, name: string }>('SELECT id, name FROM Users'); // `users` will be an array of the provided type
Works with both .all
and .get
.
Use questions marks in your sql query to use variables:
const comment = await db.get('SELECT * FROM Comments WHERE id = ?', [commentId]);