mirror of
https://github.com/allankoechke/turso.git
synced 2026-12-03 17:49:28 +00:00
Update vitest from 3.2.7 to 4.1.11 to pick up the fix for the @vitest/mocker advisory: before 4.1.11, a client that can reach the dev server can register a redirect mock pointing at any file and read that file's contents. 4.1.11 checks the target against the dev server's allowed files. Vitest 4 moved Playwright browser support into a separate package, so the wasm packages (`packages/wasm`, `sync/packages/wasm`) now depend on `@vitest/browser-playwright` instead of `@vitest/browser`, and their `vitest.config.ts` passes `provider: playwright()`. Note: vitest 4 resolves its own vite 8.3.0, while our packages still use vite ^7.3.5 for `vite build`, so both are installed. Tests: `packages/common` tests pass on vitest 4.1.11. Native and browser tests are left to CI. Closes #9097
Turso Database for JavaScript
About
This package is the Turso in-memory database library for JavaScript.
Turso Database runs in production today at multiple organizations. It has not yet reached 1.0, so as with any database we recommend keeping backups — see the FAQ for where the project stands.
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
await 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 (?, ?)');
await insert.run('Alice', 'alice@example.com');
await insert.run('Bob', 'bob@example.com');
// Query data
const users = await 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
await 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 = await 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.transactionAsync(async (txn, users) => {
const insert = await txn.prepare('INSERT INTO users (name, email) VALUES (?, ?)');
for (const user of users) {
await insert.run(user.name, user.email);
}
});
// Execute transaction
await 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.
Related Packages
- The @tursodatabase/serverless package provides a serverless driver with the same API.
- The @tursodatabase/sync package provides bidirectional sync between a local Turso database and Turso Cloud.
License
This project is licensed under the MIT license.