limbo/bindings/javascript
Pekka Enberg c2208a542a
Merge 'Initial pass to support per page encryption' from Avinash Sajjanshetty
This patch adds support for per page encryption. The code is of alpha
quality, was to test my hypothesis. All the encryption code is gated
behind a `encryption` flag. To play with it, you can do:
```sh
cargo run --features encryption -- database.db

turso> PRAGMA key='turso_test_encryption_key_123456';

turso> CREATE TABLE t(v);
```
Right now, most stuff is hard coded. We use AES GCM 256. This
information is not stored anywhere, but in future versions we will start
saving this info in the file. When writing to disk, we will generate a
cryptographically secure random salt, use that to encrypt the page. Then
we will store the authentication tag and the salt in the page itself. To
accommodate this encryption hardcodes reserved space of 28 bytes.
Once the key is set in the connection, we propagate that information to
pager and the WAL, to encrypt / decrypt when reading from disk.

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #2567
2025-08-20 11:11:24 +03: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
examples/drizzle Rename JavaScript package to @tursodatabase/database 2025-08-08 13:22:10 +03:00
perf Rename JavaScript package to @tursodatabase/database 2025-08-08 13:22:10 +03:00
src simplify feature flag usage for encryption 2025-08-20 12:49:38 +05:30
.gitignore Disable extension loading for wasm 2025-07-28 14:49:07 -03:00
.npmignore Initial JavaScript bindings with napi-rs 2025-03-26 13:30:13 +02:00
.yarnrc.yml Remove wasm binding 2025-07-28 14:48:51 -03:00
bind.ts setup dual publish for commonjs/esm modules and properly route browser/node usages to the correct napi binary entrypoint 2025-08-07 16:28:02 +04:00
browser.js Rename JavaScript package to @tursodatabase/database 2025-08-08 13:22:10 +03:00
build.rs Initial JavaScript bindings with napi-rs 2025-03-26 13:30:13 +02:00
Cargo.toml fix Database storage for WASM bindings 2025-08-20 11:47:25 +05:30
compat.ts javascript: Implement transactions API 2025-08-19 16:35:44 +03:00
index.d.ts javascript: Implement Statement.columns() 2025-08-19 16:35:44 +03:00
index.js Rename JavaScript package to @tursodatabase/database 2025-08-08 13:22:10 +03:00
package-lock.json Turso 0.1.4 2025-08-20 10:35:35 +03:00
package.json Turso 0.1.4 2025-08-20 10:35:35 +03:00
promise.ts javascript: Implement transactions API 2025-08-19 16:35:44 +03:00
README.md Unify JavaScript package README files 2025-08-12 19:30:02 +03:00
sqlite-error.ts setup dual publish for commonjs/esm modules and properly route browser/node usages to the correct napi binary entrypoint 2025-08-07 16:28:02 +04:00
tsconfig.json simplify setup by emiting index.js in ESM style from napi 2025-08-08 00:47:37 +04:00
turso.wasi-browser.js Remove wasm binding 2025-07-28 14:48:51 -03:00
turso.wasi.cjs Rename JavaScript package to @tursodatabase/database 2025-08-08 13:22:10 +03:00
wasi-worker-browser.mjs Remove wasm binding 2025-07-28 14:48:51 -03:00
wasi-worker.mjs Remove wasm binding 2025-07-28 14:48:51 -03:00
yarn.lock Rename JavaScript package to @tursodatabase/database 2025-08-08 13:22:10 +03: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 ALPHA, only use for development, testing, and experimentation. We are working to make it production ready, but do not use it for critical data right now.

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, 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