libSQL is an open source, open contribution fork of SQLite. This source repository contains libSQL API bindings for Node, which aims to be compatible with better-sqlite3, but with opt-in promise API.
- In-memory databases and local database files, like SQLite
- Remote database access to libSQL server
- In-app replica that syncs with a libSQL server
You can install the package with npm
:
npm i libsql-experimental
To try out your first libsql program, type the following in hello.js
:
import Database from 'libsql-experimental';
const db = new Database(':memory:');
db.exec("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)");
db.exec("INSERT INTO users (id, name, email) VALUES (1, 'Alice', 'alice@example.org')");
const row = db.prepare("SELECT * FROM users WHERE id = ?").get(1);
console.log(`Name: ${row.name}, email: ${row.email}`);
and then run:
$ node hello.js
To use the promise API, import libsql-experimental/promise
:
import Database from 'libsql-experimental/promise';
const db = new Database(':memory:');
await db.exec("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)");
await db.exec("INSERT INTO users (id, name, email) VALUES (1, 'Alice', 'alice@example.org')");
const stmt = await db.prepare("SELECT * FROM users WHERE id = ?");
const row = stmt.get(1);
console.log(`Name: ${row.name}, email: ${row.email}`);
import Database from 'libsql-experimental';
const db = new Database('hello.db');
import Database from 'libsql-experimental';
const url = process.env.LIBSQL_URL;
const authToken = process.env.LIBSQL_AUTH_TOKEN;
const opts = {
authToken: authToken,
};
const db = new Database(url, opts);
import libsql_experimental as libsql
const opts = { syncUrl: "<url>", authToken: "<optional auth token>" };
const db = new Database('hello.db', opts);
db.sync();
db.exec("CREATE TABLE users (id INTEGER, email TEXT);")
db.exec("INSERT INTO users VALUES (1, 'alice@example.org')")
const row = db.prepare("SELECT * FROM users WHERE id = ?").get(1);
To build the libsql
package, run:
npm run build
You can then run the integration tests with:
npm link
cd integration-tests
npm link libsql-experimental
npm test
This project is licensed under the MIT license.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in libSQL by you, shall be licensed as MIT, without any additional terms or conditions.