limbo/bindings/javascript
Pekka Enberg 1f79fbc22c
Merge 'Partial sync basic' from Nikita Sivukhin
This PR implements basic support for partial sync. Right now the scope
is limited to only `:memory:` IO and later will be properly expanded to
the file based IO later.
The main addition is `PartialDatabaseStorage` which make request to the
remote server for missing local pages on demand.
The main change is that now tursodatabase JS bindings accept optional
"external" IO event loop which in case of sync will drive `ProtocolIo`
internal work associated with remote page fetching tasks.

Closes #3931
2025-11-13 16:38:04 +02:00
..
.yarn/releases bind/js: Switch to napi v3 2025-07-25 11:45:57 -03:00
docs add formatting instructions for js 2025-07-01 11:11:36 -04:00
packages integrate extra io stepping logic to the JS bindings 2025-11-12 10:53:25 +04:00
perf move compute to the main thread for browser and node 2025-09-19 13:19:30 +04:00
scripts hack imports of wasm due to the issues in Vite and Next.js build systems 2025-09-12 14:03:31 +04:00
src use dyn DatabaseStorage instead of DatabaseFile 2025-11-06 17:42:03 +04:00
sync Merge 'Partial sync basic' from Nikita Sivukhin 2025-11-13 16:38:04 +02:00
.gitignore add sync node example 2025-10-03 14:18:52 +04:00
.npmignore final adjustments 2025-09-09 14:06:10 +04:00
.yarnrc.yml Remove wasm binding 2025-07-28 14:48:51 -03:00
build.rs Initial JavaScript bindings with napi-rs 2025-03-26 13:30:13 +02:00
Cargo.toml enable encryption feature flag by default 2025-09-30 19:04:25 +05:30
Makefile javascript: Rename "browser" packages to "wasm" 2025-09-29 17:02:34 +03:00
package-lock.json Turso 0.4.0-pre.1 2025-11-06 08:33:13 +02:00
package.json Turso 0.4.0-pre.1 2025-11-06 08:33:13 +02:00
README.md Beta 2025-10-01 07:18:25 +03:00
replace.sh use wasm-runtime from NPM instead of patched sources 2025-09-23 12:28:16 +04:00
yarn.lock Turso 0.4.0-pre.1 2025-11-06 08:33:13 +02:00

Turso Database for JavaScript

npm

Chat with other users of Turso on Discord


About

This package is the Turso in-memory database library for JavaScript.

⚠️ Warning: This software is in BETA. It may still contain bugs and unexpected behavior. Use caution with production data and ensure you have backups.

Features

  • SQLite compatible: SQLite query language and file format support (status).
  • In-process: No network overhead, runs directly in your Node.js process
  • TypeScript support: Full TypeScript definitions included
  • Cross-platform: Supports Linux (x86 and arm64), macOS, Windows and browsers (through WebAssembly)

Installation

npm install @tursodatabase/database

Getting Started

In-Memory Database

import { connect } from '@tursodatabase/database';

// Create an in-memory database
const db = await connect(':memory:');

// Create a table
db.exec('CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)');

// Insert data
const insert = db.prepare('INSERT INTO users (name, email) VALUES (?, ?)');
insert.run('Alice', 'alice@example.com');
insert.run('Bob', 'bob@example.com');

// Query data
const users = db.prepare('SELECT * FROM users').all();
console.log(users);
// Output: [
//   { id: 1, name: 'Alice', email: 'alice@example.com' },
//   { id: 2, name: 'Bob', email: 'bob@example.com' }
// ]

File-Based Database

import { connect } from '@tursodatabase/database';

// Create or open a database file
const db = await connect('my-database.db');

// Create a table
db.exec(`
  CREATE TABLE IF NOT EXISTS posts (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    title TEXT NOT NULL,
    content TEXT,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP
  )
`);

// Insert a post
const insertPost = db.prepare('INSERT INTO posts (title, content) VALUES (?, ?)');
const result = insertPost.run('Hello World', 'This is my first blog post!');

console.log(`Inserted post with ID: ${result.lastInsertRowid}`);

Transactions

import { connect } from '@tursodatabase/database';

const db = await connect('transactions.db');

// Using transactions for atomic operations
const transaction = db.transaction((users) => {
  const insert = db.prepare('INSERT INTO users (name, email) VALUES (?, ?)');
  for (const user of users) {
    insert.run(user.name, user.email);
  }
});

// Execute transaction
transaction([
  { name: 'Alice', email: 'alice@example.com' },
  { name: 'Bob', email: 'bob@example.com' }
]);

WebAssembly Support

Turso Database can run in browsers using WebAssembly. Check the browser.js and WASM artifacts for browser usage.

API Reference

For complete API documentation, see JavaScript API Reference.

License

This project is licensed under the MIT license.

Support