Files
turso/bindings/javascript
Pekka Enberg 7a09eb0d4c Merge 'Fix JavaScript bindings packaging' from Nikita Sivukhin
This PR configure `#entry-point` import alias for javascript bindings in
order to use `browser.js` napi-rs generated file in browser context.
Also, this PR forces napi-rs to emit `index.js` entrypoint using ESM and
also use typescript for writing our wrapper code around napi-rs
bindings.
In order to make behaviour consistent when lib is imported through ESM
or CommonJS this PR also replace default export of `Database` by named
on. The problem is that `export default Database` will be logically
equivalent to `modules.export.default = Database` which is not the same
thing as `modules.export = Database` and this will need to access
additional `.default` field with CommonJs style imports (e.g. `new
require('@tursodatabase/turso').default(...)`). In order to remove this
difference - I just replaced default export with named one.

Closes #2488
2025-08-08 10:42:21 +03:00
..
2025-07-25 11:45:57 -03:00
2025-07-01 11:11:36 -04:00
2025-08-08 00:48:20 +04:00
2025-07-28 14:49:07 -03:00
2025-07-28 14:48:51 -03:00
2025-07-28 14:48:51 -03:00
2025-08-08 10:34:11 +04:00
2025-07-28 17:07:34 -03:00
2025-07-28 14:48:51 -03:00
2025-07-28 14:48:51 -03:00
2025-07-28 14:48:51 -03:00
2025-07-28 14:48:51 -03:00

@tursodatabase/turso

The next evolution of SQLite: A high-performance, SQLite-compatible database library for Node.js

Features

  • SQLite Compatible: Drop-in replacement for better-sqlite3 with familiar API
  • High Performance: Built with Rust for maximum speed and efficiency
  • 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)
  • Transaction Support: Full ACID transactions with rollback support
  • Prepared Statements: Optimized query execution with parameter binding

Installation

npm install @tursodatabase/turso

Quick Start

In-Memory Database

import Database from '@tursodatabase/turso';

// Create an in-memory database
const db = new Database(':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 Database from '@tursodatabase/turso';

// Create or open a database file
const db = new Database('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}`);

API Reference

License

MIT

Support