- Notifications
You must be signed in to change notification settings - Fork42
A better-sqlite3 compatible API for libSQL that supports Node, Bun, and Deno.
License
tursodatabase/libsql-js
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
libSQL is an open source, open contribution fork of SQLite.This source repository contains libSQL API bindings for Node, which aims to be compatible withbetter-sqlite3, but with opt-in promise API.
Please note that there is also thelibSQL SDK, which is useful if you don't needbetter-sqlite3 compatibility or use libSQL in environments like serverless functions that requirefetch()-based database access protocol.
- In-memory and local libSQL/SQLite databases
- Remote libSQL databases
- Embedded, in-app replica that syncs with a remote libSQL database
- Supports Bun, Deno, and Node on macOS, Linux, and Windows.
You can install the package with:
Node:
npm i libsql
Bun:
bun add libsql
Deno:
Use thenpm: prefix for package import:
importDatabasefrom'npm:libsql';
To try out your first libsql program, type the following inhello.js:
importDatabasefrom'libsql';constdb=newDatabase(':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')");constrow=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, importlibsql/promise:
importDatabasefrom'libsql/promise';constdb=newDatabase(':memory:');awaitdb.exec("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)");awaitdb.exec("INSERT INTO users (id, name, email) VALUES (1, 'Alice', 'alice@example.org')");conststmt=awaitdb.prepare("SELECT * FROM users WHERE id = ?");constrow=stmt.get(1);console.log(`Name:${row.name}, email:${row.email}`);
importDatabasefrom'libsql';constdb=newDatabase('hello.db');
importDatabasefrom'libsql';consturl=process.env.LIBSQL_URL;constauthToken=process.env.LIBSQL_AUTH_TOKEN;constopts={authToken:authToken,};constdb=newDatabase(url,opts);
importlibsqlconstopts={syncUrl:"<url>",authToken:"<optional auth token>"};constdb=newDatabase('hello.db',opts);db.sync();
db.exec("CREATE TABLE users (id INTEGER, email TEXT);")
db.exec("INSERT INTO users VALUES (1, 'alice@example.org')")
constrow=db.prepare("SELECT * FROM users WHERE id = ?").get(1);
To build thelibsql package, run:
LIBSQL_JS_DEV=1 npm run buildYou can then run the integration tests with:
export LIBSQL_JS_DEV=1npm linkcd integration-testsnpm link libsqlnpm test
This project is licensed under theMIT license.
Unless you explicitly state otherwise, any contribution intentionally submittedfor inclusion in libSQL by you, shall be licensed as MIT, without any additionalterms or conditions.
About
A better-sqlite3 compatible API for libSQL that supports Node, Bun, and Deno.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.