Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A better-sqlite3 compatible API for libSQL that supports Node, Bun, and Deno.

License

NotificationsYou must be signed in to change notification settings

tursodatabase/libsql-js

Repository files navigation

npmAsk AI

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.

Features

  • 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.

Installing

You can install the package with:

Node:

npm i libsql

Bun:

bun add libsql

Deno:

Use thenpm: prefix for package import:

importDatabasefrom'npm:libsql';

Documentation

Getting Started

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}`);

Connecting to a local database file

importDatabasefrom'libsql';constdb=newDatabase('hello.db');

Connecting to a Remote libSQL server

importDatabasefrom'libsql';consturl=process.env.LIBSQL_URL;constauthToken=process.env.LIBSQL_AUTH_TOKEN;constopts={authToken:authToken,};constdb=newDatabase(url,opts);

Creating an in-app replica and syncing it

importlibsqlconstopts={syncUrl:"<url>",authToken:"<optional auth token>"};constdb=newDatabase('hello.db',opts);db.sync();

Creating a table

db.exec("CREATE TABLE users (id INTEGER, email TEXT);")

Inserting rows into a table

db.exec("INSERT INTO users VALUES (1, 'alice@example.org')")

Querying rows from a table

constrow=db.prepare("SELECT * FROM users WHERE id = ?").get(1);

Developing

To build thelibsql package, run:

LIBSQL_JS_DEV=1 npm run build

You can then run the integration tests with:

export LIBSQL_JS_DEV=1npm linkcd integration-testsnpm link libsqlnpm test

License

This project is licensed under theMIT license.

Contribution

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

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp