final adjustments

This commit is contained in:
Nikita Sivukhin
2025-09-09 14:00:10 +04:00
parent 69aebd5a88
commit 7618dfb519
18 changed files with 330 additions and 107 deletions

View File

@@ -135,13 +135,15 @@ jobs:
node-version: ${{ matrix.node }} node-version: ${{ matrix.node }}
- name: Install dependencies - name: Install dependencies
run: yarn install run: yarn install
- name: Install dependencies - name: Build core
run: yarn build run: yarn workspace @tursodatabase/database-core build
- name: Build native
run: yarn workspace @tursodatabase/database build
- name: Download artifacts - name: Download artifacts
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
with: with:
name: bindings-x86_64-unknown-linux-gnu name: bindings-x86_64-unknown-linux-gnu
path: bindings/javascript/ path: bindings/javascript/packages/native
- name: List packages - name: List packages
run: ls -R . run: ls -R .
shell: bash shell: bash
@@ -162,10 +164,16 @@ jobs:
uses: useblacksmith/setup-node@v5 uses: useblacksmith/setup-node@v5
with: with:
node-version: 20 node-version: 20
- name: Download all artifacts - name: Download native artifacts
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
with: with:
path: bindings/javascript path: bindings/javascript/packages/native
pattern: '*.node'
- name: Download browser artifacts
uses: actions/download-artifact@v4
with:
path: bindings/javascript/packages/browser
pattern: '*.wasm'
- name: Install dependencies - name: Install dependencies
run: yarn install run: yarn install
- name: Install dependencies - name: Install dependencies
@@ -176,13 +184,13 @@ jobs:
if git log -1 --pretty=%B | grep "^Turso [0-9]\+\.[0-9]\+\.[0-9]\+$"; if git log -1 --pretty=%B | grep "^Turso [0-9]\+\.[0-9]\+\.[0-9]\+$";
then then
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
npm publish --access public npm publish --workspaces --access public
elif git log -1 --pretty=%B | grep "^Turso [0-9]\+\.[0-9]\+\.[0-9]\+"; elif git log -1 --pretty=%B | grep "^Turso [0-9]\+\.[0-9]\+\.[0-9]\+";
then then
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
npm publish --access public --tag next npm publish --workspaces --access public --tag next
else else
npm publish --dry-run npm publish --workspaces --dry-run
fi fi
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -11,3 +11,5 @@ yarn.lock
.yarn .yarn
__test__ __test__
renovate.json renovate.json
examples
perf

View File

@@ -56,7 +56,6 @@
"version": "1.4.5", "version": "1.4.5",
"resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.4.5.tgz", "resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.4.5.tgz",
"integrity": "sha512-XsLw1dEOpkSX/WucdqUhPWP7hDxSvZiY+fsUC14h+FtQ2Ifni4znbBt8punRX+Uj2JG/uDb8nEHVKvrVlvdZ5Q==", "integrity": "sha512-XsLw1dEOpkSX/WucdqUhPWP7hDxSvZiY+fsUC14h+FtQ2Ifni4znbBt8punRX+Uj2JG/uDb8nEHVKvrVlvdZ5Q==",
"dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@emnapi/wasi-threads": "1.0.4", "@emnapi/wasi-threads": "1.0.4",
@@ -67,7 +66,6 @@
"version": "1.4.5", "version": "1.4.5",
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.4.5.tgz", "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.4.5.tgz",
"integrity": "sha512-++LApOtY0pEEz1zrd9vy1/zXVaVJJ/EbAF3u0fXIzPJEDtnITsBGbbK0EkM72amhl/R5b+5xx0Y/QhcVOpuulg==", "integrity": "sha512-++LApOtY0pEEz1zrd9vy1/zXVaVJJ/EbAF3u0fXIzPJEDtnITsBGbbK0EkM72amhl/R5b+5xx0Y/QhcVOpuulg==",
"dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"tslib": "^2.4.0" "tslib": "^2.4.0"
@@ -77,7 +75,6 @@
"version": "1.0.4", "version": "1.0.4",
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.0.4.tgz", "resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.0.4.tgz",
"integrity": "sha512-PJR+bOmMOPH8AtcTGAyYNiuJ3/Fcoj2XN/gBEWzDIKh254XO+mM9XoXHk5GNEhodxeMznbg7BlRojVbKN+gC6g==", "integrity": "sha512-PJR+bOmMOPH8AtcTGAyYNiuJ3/Fcoj2XN/gBEWzDIKh254XO+mM9XoXHk5GNEhodxeMznbg7BlRojVbKN+gC6g==",
"dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"tslib": "^2.4.0" "tslib": "^2.4.0"
@@ -778,7 +775,6 @@
"version": "1.0.3", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.0.3.tgz", "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.0.3.tgz",
"integrity": "sha512-rZxtMsLwjdXkMUGC3WwsPwLNVqVqnTJT6MNIB6e+5fhMcSCPP0AOsNWuMQ5mdCq6HNjs/ZeWAEchpqeprqBD2Q==", "integrity": "sha512-rZxtMsLwjdXkMUGC3WwsPwLNVqVqnTJT6MNIB6e+5fhMcSCPP0AOsNWuMQ5mdCq6HNjs/ZeWAEchpqeprqBD2Q==",
"dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@emnapi/core": "^1.4.5", "@emnapi/core": "^1.4.5",
@@ -1113,7 +1109,6 @@
"version": "0.10.0", "version": "0.10.0",
"resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.0.tgz", "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.0.tgz",
"integrity": "sha512-VyyPYFlOMNylG45GoAe0xDoLwWuowvf92F9kySqzYh8vmYm7D2u4iUJKa1tOUpS70Ku13ASrOkS4ScXFsTaCNQ==", "integrity": "sha512-VyyPYFlOMNylG45GoAe0xDoLwWuowvf92F9kySqzYh8vmYm7D2u4iUJKa1tOUpS70Ku13ASrOkS4ScXFsTaCNQ==",
"dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"tslib": "^2.4.0" "tslib": "^2.4.0"
@@ -2210,7 +2205,6 @@
"version": "2.8.1", "version": "2.8.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
"dev": true,
"license": "0BSD" "license": "0BSD"
}, },
"node_modules/typanion": { "node_modules/typanion": {
@@ -2489,14 +2483,14 @@
}, },
"packages/browser": { "packages/browser": {
"name": "@tursodatabase/database-browser", "name": "@tursodatabase/database-browser",
"version": "0.1.5-pre.4", "version": "0.1.5-pre.3",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@tursodatabase/database-core": "^0.1.5-pre.4" "@napi-rs/wasm-runtime": "^1.0.3",
"@tursodatabase/database-core": "^0.1.5-pre.3"
}, },
"devDependencies": { "devDependencies": {
"@napi-rs/cli": "^3.1.5", "@napi-rs/cli": "^3.1.5",
"@napi-rs/wasm-runtime": "^1.0.3",
"@vitest/browser": "^3.2.4", "@vitest/browser": "^3.2.4",
"playwright": "^1.55.0", "playwright": "^1.55.0",
"typescript": "^5.9.2", "typescript": "^5.9.2",
@@ -2505,7 +2499,7 @@
}, },
"packages/core": { "packages/core": {
"name": "@tursodatabase/database-core", "name": "@tursodatabase/database-core",
"version": "0.1.5-pre.4", "version": "0.1.5-pre.3",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"typescript": "^5.9.2" "typescript": "^5.9.2"
@@ -2513,14 +2507,13 @@
}, },
"packages/native": { "packages/native": {
"name": "@tursodatabase/database", "name": "@tursodatabase/database",
"version": "0.1.5-pre.4", "version": "0.1.5-pre.3",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@tursodatabase/database-core": "^0.1.5-pre.4" "@tursodatabase/database-core": "^0.1.5-pre.3"
}, },
"devDependencies": { "devDependencies": {
"@napi-rs/cli": "^3.1.5", "@napi-rs/cli": "^3.1.5",
"@napi-rs/wasm-runtime": "^1.0.3",
"@types/node": "^24.3.1", "@types/node": "^24.3.1",
"typescript": "^5.9.2", "typescript": "^5.9.2",
"vitest": "^3.2.4" "vitest": "^3.2.4"

View File

@@ -0,0 +1,124 @@
<p align="center">
<h1 align="center">Turso Database for JavaScript in Browser</h1>
</p>
<p align="center">
<a title="JavaScript" target="_blank" href="https://www.npmjs.com/package/@tursodatabase/database"><img alt="npm" src="https://img.shields.io/npm/v/@tursodatabase/database"></a>
<a title="MIT" target="_blank" href="https://github.com/tursodatabase/turso/blob/main/LICENSE.md"><img src="http://img.shields.io/badge/license-MIT-orange.svg?style=flat-square"></a>
</p>
<p align="center">
<a title="Users Discord" target="_blank" href="https://tur.so/discord"><img alt="Chat with other users of Turso on Discord" src="https://img.shields.io/discord/933071162680958986?label=Discord&logo=Discord&style=social"></a>
</p>
---
## About
This package is the Turso embedded database library for JavaScript in Browser.
> **⚠️ 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](https://github.com/tursodatabase/turso/blob/main/COMPAT.md)).
- **In-process**: No network overhead, runs directly in your Node.js process
- **TypeScript support**: Full TypeScript definitions included
## Installation
```bash
npm install @tursodatabase/database-browser
```
## Getting Started
### In-Memory Database
```javascript
import { connect } from '@tursodatabase/database-browser';
// 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
```javascript
import { connect } from '@tursodatabase/database-browser';
// 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
```javascript
import { connect } from '@tursodatabase/database-browser';
const db = await connect('transactions.db');
// Using transactions for atomic operations
const transaction = db.transaction(async (users) => {
const insert = db.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' }
]);
```
## API Reference
For complete API documentation, see [JavaScript API Reference](../../../../docs/javascript-api-reference.md).
## Related Packages
* The [@tursodatabase/serverless](https://www.npmjs.com/package/@tursodatabase/serverless) package provides a serverless driver with the same API.
* The [@tursodatabase/sync](https://www.npmjs.com/package/@tursodatabase/sync) package provides bidirectional sync between a local Turso database and Turso Cloud.
## License
This project is licensed under the [MIT license](../../LICENSE.md).
## Support
- [GitHub Issues](https://github.com/tursodatabase/turso/issues)
- [Documentation](https://docs.turso.tech)
- [Discord Community](https://tur.so/discord)

View File

@@ -1,22 +1,22 @@
{ {
"name": "@tursodatabase/database-browser", "name": "@tursodatabase/database-browser",
"version": "0.1.5-pre.4", "version": "0.1.5-pre.3",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/tursodatabase/turso" "url": "https://github.com/tursodatabase/turso"
}, },
"license": "MIT", "license": "MIT",
"main": "index.js", "main": "dist/promise.js",
"packageManager": "yarn@4.9.2", "packageManager": "yarn@4.9.2",
"files": [ "files": [
"index.js", "index.js",
"worker.mjs", "worker.mjs",
"turso.wasm32-wasi.wasm", "turso.wasm32-wasi.wasm",
"dist/**" "dist/**",
"README.md"
], ],
"devDependencies": { "devDependencies": {
"@napi-rs/cli": "^3.1.5", "@napi-rs/cli": "^3.1.5",
"@napi-rs/wasm-runtime": "^1.0.3",
"@vitest/browser": "^3.2.4", "@vitest/browser": "^3.2.4",
"playwright": "^1.55.0", "playwright": "^1.55.0",
"typescript": "^5.9.2", "typescript": "^5.9.2",
@@ -34,7 +34,11 @@
"wasm32-wasip1-threads" "wasm32-wasip1-threads"
] ]
}, },
"imports": {
"#index": "./index.js"
},
"dependencies": { "dependencies": {
"@tursodatabase/database-core": "^0.1.5-pre.4" "@napi-rs/wasm-runtime": "^1.0.3",
"@tursodatabase/database-core": "^0.1.5-pre.3"
} }
} }

View File

@@ -20,6 +20,7 @@ test('on-disk db', async () => {
const rows1 = await stmt1.all([1]); const rows1 = await stmt1.all([1]);
expect(rows1).toEqual([{ x: 1 }, { x: 3 }]); expect(rows1).toEqual([{ x: 1 }, { x: 3 }]);
await db1.close(); await db1.close();
stmt1.close();
const db2 = await connect(path); const db2 = await connect(path);
const stmt2 = db2.prepare("SELECT * FROM t WHERE x % 2 = ?"); const stmt2 = db2.prepare("SELECT * FROM t WHERE x % 2 = ?");
@@ -53,3 +54,42 @@ test('blobs', async () => {
expect(rows).toEqual([{ x: new Uint8Array([16, 32]) }]) expect(rows).toEqual([{ x: new Uint8Array([16, 32]) }])
}) })
test('example-1', async () => {
const db = await connect(':memory:');
await db.exec('CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)');
const insert = db.prepare('INSERT INTO users (name, email) VALUES (?, ?)');
await insert.run('Alice', 'alice@example.com');
await insert.run('Bob', 'bob@example.com');
const users = await db.prepare('SELECT * FROM users').all();
expect(users).toEqual([
{ id: 1, name: 'Alice', email: 'alice@example.com' },
{ id: 2, name: 'Bob', email: 'bob@example.com' }
]);
})
test('example-2', async () => {
const db = await connect(':memory:');
await db.exec('CREATE TABLE users (name, email)');
// Using transactions for atomic operations
const transaction = db.transaction(async (users) => {
const insert = db.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' }
]);
const rows = await db.prepare('SELECT * FROM users').all();
expect(rows).toEqual([
{ name: 'Alice', email: 'alice@example.com' },
{ name: 'Bob', email: 'bob@example.com' }
]);
})

View File

@@ -1,5 +1,5 @@
import { DatabasePromise, NativeDatabase, DatabaseOpts, SqliteError } from "@tursodatabase/database-core" import { DatabasePromise, NativeDatabase, DatabaseOpts, SqliteError } from "@tursodatabase/database-core"
import { connect as nativeConnect, initThreadPool, MainWorker } from "./index.js"; import { connect as nativeConnect, initThreadPool, MainWorker } from "#index";
let workerRequestId = 0; let workerRequestId = 0;
class Database extends DatabasePromise { class Database extends DatabasePromise {

View File

@@ -9,6 +9,11 @@
"lib": [ "lib": [
"es2020" "es2020"
], ],
"paths": {
"#index": [
"./index.js"
]
}
}, },
"include": [ "include": [
"*" "*"

View File

@@ -0,0 +1,8 @@
## About
This package is the Turso embedded database common JS library which is shared between final builds for Node and Browser.
Do not use this package directly - instead you must use `@tursodatabase/database` or `@tursodatabase/database-browser`.
> **⚠️ 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.

View File

@@ -1,6 +1,6 @@
{ {
"name": "@tursodatabase/database-core", "name": "@tursodatabase/database-core",
"version": "0.1.5-pre.4", "version": "0.1.5-pre.3",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/tursodatabase/turso" "url": "https://github.com/tursodatabase/turso"
@@ -11,7 +11,8 @@
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
"packageManager": "yarn@4.9.2", "packageManager": "yarn@4.9.2",
"files": [ "files": [
"dist/**" "dist/**",
"README.md"
], ],
"devDependencies": { "devDependencies": {
"typescript": "^5.9.2" "typescript": "^5.9.2"

View File

@@ -414,5 +414,9 @@ class Statement {
throw convertError(err); throw convertError(err);
} }
} }
close() {
this.stmt.finalize();
}
} }
export { Database, Statement } export { Database, Statement }

View File

@@ -42,4 +42,5 @@ export interface NativeStatement {
columns(): string[]; columns(): string[];
row(): any; row(): any;
reset(); reset();
finalize();
} }

View File

@@ -1,5 +1,5 @@
<p align="center"> <p align="center">
<h1 align="center">Turso Database for JavaScript</h1> <h1 align="center">Turso Database for JavaScript in Node</h1>
</p> </p>
<p align="center"> <p align="center">
@@ -14,7 +14,7 @@
## About ## About
This package is the Turso embedded database library for JavaScript. This package is the Turso embedded database library for JavaScript in Node.
> **⚠️ 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. > **⚠️ 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.
@@ -23,7 +23,7 @@ This package is the Turso embedded database library for JavaScript.
- **SQLite compatible:** SQLite query language and file format support ([status](https://github.com/tursodatabase/turso/blob/main/COMPAT.md)). - **SQLite compatible:** SQLite query language and file format support ([status](https://github.com/tursodatabase/turso/blob/main/COMPAT.md)).
- **In-process**: No network overhead, runs directly in your Node.js process - **In-process**: No network overhead, runs directly in your Node.js process
- **TypeScript support**: Full TypeScript definitions included - **TypeScript support**: Full TypeScript definitions included
- **Cross-platform**: Supports Linux (x86 and arm64), macOS, Windows and browsers (through WebAssembly) - **Cross-platform**: Supports Linux (x86 and arm64), macOS, Windows (browser is supported in the separate package `@tursodatabase/database-browser` package)
## Installation ## Installation
@@ -42,15 +42,15 @@ import { connect } from '@tursodatabase/database';
const db = await connect(':memory:'); const db = await connect(':memory:');
// Create a table // Create a table
db.exec('CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)'); await db.exec('CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)');
// Insert data // Insert data
const insert = db.prepare('INSERT INTO users (name, email) VALUES (?, ?)'); const insert = db.prepare('INSERT INTO users (name, email) VALUES (?, ?)');
insert.run('Alice', 'alice@example.com'); await insert.run('Alice', 'alice@example.com');
insert.run('Bob', 'bob@example.com'); await insert.run('Bob', 'bob@example.com');
// Query data // Query data
const users = db.prepare('SELECT * FROM users').all(); const users = await db.prepare('SELECT * FROM users').all();
console.log(users); console.log(users);
// Output: [ // Output: [
// { id: 1, name: 'Alice', email: 'alice@example.com' }, // { id: 1, name: 'Alice', email: 'alice@example.com' },
@@ -67,7 +67,7 @@ import { connect } from '@tursodatabase/database';
const db = await connect('my-database.db'); const db = await connect('my-database.db');
// Create a table // Create a table
db.exec(` await db.exec(`
CREATE TABLE IF NOT EXISTS posts ( CREATE TABLE IF NOT EXISTS posts (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL, title TEXT NOT NULL,
@@ -78,7 +78,7 @@ db.exec(`
// Insert a post // Insert a post
const insertPost = db.prepare('INSERT INTO posts (title, content) VALUES (?, ?)'); const insertPost = db.prepare('INSERT INTO posts (title, content) VALUES (?, ?)');
const result = insertPost.run('Hello World', 'This is my first blog post!'); const result = await insertPost.run('Hello World', 'This is my first blog post!');
console.log(`Inserted post with ID: ${result.lastInsertRowid}`); console.log(`Inserted post with ID: ${result.lastInsertRowid}`);
``` ```
@@ -91,24 +91,20 @@ import { connect } from '@tursodatabase/database';
const db = await connect('transactions.db'); const db = await connect('transactions.db');
// Using transactions for atomic operations // Using transactions for atomic operations
const transaction = db.transaction((users) => { const transaction = db.transaction(async (users) => {
const insert = db.prepare('INSERT INTO users (name, email) VALUES (?, ?)'); const insert = db.prepare('INSERT INTO users (name, email) VALUES (?, ?)');
for (const user of users) { for (const user of users) {
insert.run(user.name, user.email); await insert.run(user.name, user.email);
} }
}); });
// Execute transaction // Execute transaction
transaction([ await transaction([
{ name: 'Alice', email: 'alice@example.com' }, { name: 'Alice', email: 'alice@example.com' },
{ name: 'Bob', email: 'bob@example.com' } { name: 'Bob', email: 'bob@example.com' }
]); ]);
``` ```
### WebAssembly Support
Turso Database can run in browsers using WebAssembly from separate package. Check the `@tursodatabase/database-browser` for more details.
## API Reference ## API Reference
For complete API documentation, see [JavaScript API Reference](../../../../docs/javascript-api-reference.md). For complete API documentation, see [JavaScript API Reference](../../../../docs/javascript-api-reference.md).

View File

@@ -81,8 +81,8 @@ function requireNative() {
try { try {
const binding = require('@tursodatabase/database-android-arm64') const binding = require('@tursodatabase/database-android-arm64')
const bindingPackageVersion = require('@tursodatabase/database-android-arm64/package.json').version const bindingPackageVersion = require('@tursodatabase/database-android-arm64/package.json').version
if (bindingPackageVersion !== '0.1.5-pre.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { if (bindingPackageVersion !== '0.1.5-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
} }
return binding return binding
} catch (e) { } catch (e) {
@@ -97,8 +97,8 @@ function requireNative() {
try { try {
const binding = require('@tursodatabase/database-android-arm-eabi') const binding = require('@tursodatabase/database-android-arm-eabi')
const bindingPackageVersion = require('@tursodatabase/database-android-arm-eabi/package.json').version const bindingPackageVersion = require('@tursodatabase/database-android-arm-eabi/package.json').version
if (bindingPackageVersion !== '0.1.5-pre.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { if (bindingPackageVersion !== '0.1.5-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
} }
return binding return binding
} catch (e) { } catch (e) {
@@ -117,8 +117,8 @@ function requireNative() {
try { try {
const binding = require('@tursodatabase/database-win32-x64-msvc') const binding = require('@tursodatabase/database-win32-x64-msvc')
const bindingPackageVersion = require('@tursodatabase/database-win32-x64-msvc/package.json').version const bindingPackageVersion = require('@tursodatabase/database-win32-x64-msvc/package.json').version
if (bindingPackageVersion !== '0.1.5-pre.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { if (bindingPackageVersion !== '0.1.5-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
} }
return binding return binding
} catch (e) { } catch (e) {
@@ -133,8 +133,8 @@ function requireNative() {
try { try {
const binding = require('@tursodatabase/database-win32-ia32-msvc') const binding = require('@tursodatabase/database-win32-ia32-msvc')
const bindingPackageVersion = require('@tursodatabase/database-win32-ia32-msvc/package.json').version const bindingPackageVersion = require('@tursodatabase/database-win32-ia32-msvc/package.json').version
if (bindingPackageVersion !== '0.1.5-pre.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { if (bindingPackageVersion !== '0.1.5-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
} }
return binding return binding
} catch (e) { } catch (e) {
@@ -149,8 +149,8 @@ function requireNative() {
try { try {
const binding = require('@tursodatabase/database-win32-arm64-msvc') const binding = require('@tursodatabase/database-win32-arm64-msvc')
const bindingPackageVersion = require('@tursodatabase/database-win32-arm64-msvc/package.json').version const bindingPackageVersion = require('@tursodatabase/database-win32-arm64-msvc/package.json').version
if (bindingPackageVersion !== '0.1.5-pre.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { if (bindingPackageVersion !== '0.1.5-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
} }
return binding return binding
} catch (e) { } catch (e) {
@@ -168,8 +168,8 @@ function requireNative() {
try { try {
const binding = require('@tursodatabase/database-darwin-universal') const binding = require('@tursodatabase/database-darwin-universal')
const bindingPackageVersion = require('@tursodatabase/database-darwin-universal/package.json').version const bindingPackageVersion = require('@tursodatabase/database-darwin-universal/package.json').version
if (bindingPackageVersion !== '0.1.5-pre.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { if (bindingPackageVersion !== '0.1.5-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
} }
return binding return binding
} catch (e) { } catch (e) {
@@ -184,8 +184,8 @@ function requireNative() {
try { try {
const binding = require('@tursodatabase/database-darwin-x64') const binding = require('@tursodatabase/database-darwin-x64')
const bindingPackageVersion = require('@tursodatabase/database-darwin-x64/package.json').version const bindingPackageVersion = require('@tursodatabase/database-darwin-x64/package.json').version
if (bindingPackageVersion !== '0.1.5-pre.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { if (bindingPackageVersion !== '0.1.5-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
} }
return binding return binding
} catch (e) { } catch (e) {
@@ -200,8 +200,8 @@ function requireNative() {
try { try {
const binding = require('@tursodatabase/database-darwin-arm64') const binding = require('@tursodatabase/database-darwin-arm64')
const bindingPackageVersion = require('@tursodatabase/database-darwin-arm64/package.json').version const bindingPackageVersion = require('@tursodatabase/database-darwin-arm64/package.json').version
if (bindingPackageVersion !== '0.1.5-pre.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { if (bindingPackageVersion !== '0.1.5-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
} }
return binding return binding
} catch (e) { } catch (e) {
@@ -220,8 +220,8 @@ function requireNative() {
try { try {
const binding = require('@tursodatabase/database-freebsd-x64') const binding = require('@tursodatabase/database-freebsd-x64')
const bindingPackageVersion = require('@tursodatabase/database-freebsd-x64/package.json').version const bindingPackageVersion = require('@tursodatabase/database-freebsd-x64/package.json').version
if (bindingPackageVersion !== '0.1.5-pre.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { if (bindingPackageVersion !== '0.1.5-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
} }
return binding return binding
} catch (e) { } catch (e) {
@@ -236,8 +236,8 @@ function requireNative() {
try { try {
const binding = require('@tursodatabase/database-freebsd-arm64') const binding = require('@tursodatabase/database-freebsd-arm64')
const bindingPackageVersion = require('@tursodatabase/database-freebsd-arm64/package.json').version const bindingPackageVersion = require('@tursodatabase/database-freebsd-arm64/package.json').version
if (bindingPackageVersion !== '0.1.5-pre.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { if (bindingPackageVersion !== '0.1.5-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
} }
return binding return binding
} catch (e) { } catch (e) {
@@ -257,8 +257,8 @@ function requireNative() {
try { try {
const binding = require('@tursodatabase/database-linux-x64-musl') const binding = require('@tursodatabase/database-linux-x64-musl')
const bindingPackageVersion = require('@tursodatabase/database-linux-x64-musl/package.json').version const bindingPackageVersion = require('@tursodatabase/database-linux-x64-musl/package.json').version
if (bindingPackageVersion !== '0.1.5-pre.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { if (bindingPackageVersion !== '0.1.5-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
} }
return binding return binding
} catch (e) { } catch (e) {
@@ -273,8 +273,8 @@ function requireNative() {
try { try {
const binding = require('@tursodatabase/database-linux-x64-gnu') const binding = require('@tursodatabase/database-linux-x64-gnu')
const bindingPackageVersion = require('@tursodatabase/database-linux-x64-gnu/package.json').version const bindingPackageVersion = require('@tursodatabase/database-linux-x64-gnu/package.json').version
if (bindingPackageVersion !== '0.1.5-pre.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { if (bindingPackageVersion !== '0.1.5-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
} }
return binding return binding
} catch (e) { } catch (e) {
@@ -291,8 +291,8 @@ function requireNative() {
try { try {
const binding = require('@tursodatabase/database-linux-arm64-musl') const binding = require('@tursodatabase/database-linux-arm64-musl')
const bindingPackageVersion = require('@tursodatabase/database-linux-arm64-musl/package.json').version const bindingPackageVersion = require('@tursodatabase/database-linux-arm64-musl/package.json').version
if (bindingPackageVersion !== '0.1.5-pre.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { if (bindingPackageVersion !== '0.1.5-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
} }
return binding return binding
} catch (e) { } catch (e) {
@@ -307,8 +307,8 @@ function requireNative() {
try { try {
const binding = require('@tursodatabase/database-linux-arm64-gnu') const binding = require('@tursodatabase/database-linux-arm64-gnu')
const bindingPackageVersion = require('@tursodatabase/database-linux-arm64-gnu/package.json').version const bindingPackageVersion = require('@tursodatabase/database-linux-arm64-gnu/package.json').version
if (bindingPackageVersion !== '0.1.5-pre.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { if (bindingPackageVersion !== '0.1.5-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
} }
return binding return binding
} catch (e) { } catch (e) {
@@ -325,8 +325,8 @@ function requireNative() {
try { try {
const binding = require('@tursodatabase/database-linux-arm-musleabihf') const binding = require('@tursodatabase/database-linux-arm-musleabihf')
const bindingPackageVersion = require('@tursodatabase/database-linux-arm-musleabihf/package.json').version const bindingPackageVersion = require('@tursodatabase/database-linux-arm-musleabihf/package.json').version
if (bindingPackageVersion !== '0.1.5-pre.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { if (bindingPackageVersion !== '0.1.5-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
} }
return binding return binding
} catch (e) { } catch (e) {
@@ -341,8 +341,8 @@ function requireNative() {
try { try {
const binding = require('@tursodatabase/database-linux-arm-gnueabihf') const binding = require('@tursodatabase/database-linux-arm-gnueabihf')
const bindingPackageVersion = require('@tursodatabase/database-linux-arm-gnueabihf/package.json').version const bindingPackageVersion = require('@tursodatabase/database-linux-arm-gnueabihf/package.json').version
if (bindingPackageVersion !== '0.1.5-pre.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { if (bindingPackageVersion !== '0.1.5-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
} }
return binding return binding
} catch (e) { } catch (e) {
@@ -359,8 +359,8 @@ function requireNative() {
try { try {
const binding = require('@tursodatabase/database-linux-riscv64-musl') const binding = require('@tursodatabase/database-linux-riscv64-musl')
const bindingPackageVersion = require('@tursodatabase/database-linux-riscv64-musl/package.json').version const bindingPackageVersion = require('@tursodatabase/database-linux-riscv64-musl/package.json').version
if (bindingPackageVersion !== '0.1.5-pre.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { if (bindingPackageVersion !== '0.1.5-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
} }
return binding return binding
} catch (e) { } catch (e) {
@@ -375,8 +375,8 @@ function requireNative() {
try { try {
const binding = require('@tursodatabase/database-linux-riscv64-gnu') const binding = require('@tursodatabase/database-linux-riscv64-gnu')
const bindingPackageVersion = require('@tursodatabase/database-linux-riscv64-gnu/package.json').version const bindingPackageVersion = require('@tursodatabase/database-linux-riscv64-gnu/package.json').version
if (bindingPackageVersion !== '0.1.5-pre.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { if (bindingPackageVersion !== '0.1.5-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
} }
return binding return binding
} catch (e) { } catch (e) {
@@ -392,8 +392,8 @@ function requireNative() {
try { try {
const binding = require('@tursodatabase/database-linux-ppc64-gnu') const binding = require('@tursodatabase/database-linux-ppc64-gnu')
const bindingPackageVersion = require('@tursodatabase/database-linux-ppc64-gnu/package.json').version const bindingPackageVersion = require('@tursodatabase/database-linux-ppc64-gnu/package.json').version
if (bindingPackageVersion !== '0.1.5-pre.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { if (bindingPackageVersion !== '0.1.5-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
} }
return binding return binding
} catch (e) { } catch (e) {
@@ -408,8 +408,8 @@ function requireNative() {
try { try {
const binding = require('@tursodatabase/database-linux-s390x-gnu') const binding = require('@tursodatabase/database-linux-s390x-gnu')
const bindingPackageVersion = require('@tursodatabase/database-linux-s390x-gnu/package.json').version const bindingPackageVersion = require('@tursodatabase/database-linux-s390x-gnu/package.json').version
if (bindingPackageVersion !== '0.1.5-pre.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { if (bindingPackageVersion !== '0.1.5-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
} }
return binding return binding
} catch (e) { } catch (e) {
@@ -428,8 +428,8 @@ function requireNative() {
try { try {
const binding = require('@tursodatabase/database-openharmony-arm64') const binding = require('@tursodatabase/database-openharmony-arm64')
const bindingPackageVersion = require('@tursodatabase/database-openharmony-arm64/package.json').version const bindingPackageVersion = require('@tursodatabase/database-openharmony-arm64/package.json').version
if (bindingPackageVersion !== '0.1.5-pre.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { if (bindingPackageVersion !== '0.1.5-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
} }
return binding return binding
} catch (e) { } catch (e) {
@@ -444,8 +444,8 @@ function requireNative() {
try { try {
const binding = require('@tursodatabase/database-openharmony-x64') const binding = require('@tursodatabase/database-openharmony-x64')
const bindingPackageVersion = require('@tursodatabase/database-openharmony-x64/package.json').version const bindingPackageVersion = require('@tursodatabase/database-openharmony-x64/package.json').version
if (bindingPackageVersion !== '0.1.5-pre.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { if (bindingPackageVersion !== '0.1.5-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
} }
return binding return binding
} catch (e) { } catch (e) {
@@ -460,8 +460,8 @@ function requireNative() {
try { try {
const binding = require('@tursodatabase/database-openharmony-arm') const binding = require('@tursodatabase/database-openharmony-arm')
const bindingPackageVersion = require('@tursodatabase/database-openharmony-arm/package.json').version const bindingPackageVersion = require('@tursodatabase/database-openharmony-arm/package.json').version
if (bindingPackageVersion !== '0.1.5-pre.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { if (bindingPackageVersion !== '0.1.5-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) throw new Error(`Native binding package version mismatch, expected 0.1.5-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
} }
return binding return binding
} catch (e) { } catch (e) {

View File

@@ -1,6 +1,6 @@
{ {
"name": "@tursodatabase/database", "name": "@tursodatabase/database",
"version": "0.1.5-pre.4", "version": "0.1.5-pre.3",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/tursodatabase/turso" "url": "https://github.com/tursodatabase/turso"
@@ -15,12 +15,12 @@
}, },
"files": [ "files": [
"index.js", "index.js",
"dist/**" "dist/**",
"README.md"
], ],
"packageManager": "yarn@4.9.2", "packageManager": "yarn@4.9.2",
"devDependencies": { "devDependencies": {
"@napi-rs/cli": "^3.1.5", "@napi-rs/cli": "^3.1.5",
"@napi-rs/wasm-runtime": "^1.0.3",
"@types/node": "^24.3.1", "@types/node": "^24.3.1",
"typescript": "^5.9.2", "typescript": "^5.9.2",
"vitest": "^3.2.4" "vitest": "^3.2.4"
@@ -44,7 +44,7 @@
] ]
}, },
"dependencies": { "dependencies": {
"@tursodatabase/database-core": "^0.1.5-pre.4" "@tursodatabase/database-core": "^0.1.5-pre.3"
}, },
"imports": { "imports": {
"#index": "./index.js" "#index": "./index.js"

View File

@@ -65,3 +65,43 @@ test('blobs', async () => {
const rows = await db.prepare("SELECT x'1020' as x").all(); const rows = await db.prepare("SELECT x'1020' as x").all();
expect(rows).toEqual([{ x: Buffer.from([16, 32]) }]) expect(rows).toEqual([{ x: Buffer.from([16, 32]) }])
}) })
test('example-1', async () => {
const db = await connect(':memory:');
await db.exec('CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)');
const insert = db.prepare('INSERT INTO users (name, email) VALUES (?, ?)');
await insert.run('Alice', 'alice@example.com');
await insert.run('Bob', 'bob@example.com');
const users = await db.prepare('SELECT * FROM users').all();
expect(users).toEqual([
{ id: 1, name: 'Alice', email: 'alice@example.com' },
{ id: 2, name: 'Bob', email: 'bob@example.com' }
]);
})
test('example-2', async () => {
const db = await connect(':memory:');
await db.exec('CREATE TABLE users (name, email)');
// Using transactions for atomic operations
const transaction = db.transaction(async (users) => {
const insert = db.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' }
]);
const rows = await db.prepare('SELECT * FROM users').all();
expect(rows).toEqual([
{ name: 'Alice', email: 'alice@example.com' },
{ name: 'Bob', email: 'bob@example.com' }
]);
})

View File

@@ -127,9 +127,9 @@ fn step_sync(stmt: &Arc<RefCell<Option<turso_core::Statement>>>) -> napi::Result
.as_mut() .as_mut()
.ok_or_else(|| Error::new(Status::GenericFailure, "Statement has been finalized"))?; .ok_or_else(|| Error::new(Status::GenericFailure, "Statement has been finalized"))?;
let final_result = match stmt.step() { match stmt.step() {
Ok(turso_core::StepResult::Row) => return Ok(STEP_ROW), Ok(turso_core::StepResult::Row) => Ok(STEP_ROW),
Ok(turso_core::StepResult::IO) => return Ok(STEP_IO), Ok(turso_core::StepResult::IO) => Ok(STEP_IO),
Ok(turso_core::StepResult::Done) => Ok(STEP_DONE), Ok(turso_core::StepResult::Done) => Ok(STEP_DONE),
Ok(turso_core::StepResult::Interrupt) => Err(Error::new( Ok(turso_core::StepResult::Interrupt) => Err(Error::new(
Status::GenericFailure, Status::GenericFailure,
@@ -142,9 +142,7 @@ fn step_sync(stmt: &Arc<RefCell<Option<turso_core::Statement>>>) -> napi::Result
Status::GenericFailure, Status::GenericFailure,
format!("Step failed: {e}"), format!("Step failed: {e}"),
)), )),
}; }
let _ = stmt_ref.take();
final_result
} }
#[napi] #[napi]

View File

@@ -1400,7 +1400,7 @@ __metadata:
dependencies: dependencies:
"@napi-rs/cli": "npm:^3.1.5" "@napi-rs/cli": "npm:^3.1.5"
"@napi-rs/wasm-runtime": "npm:^1.0.3" "@napi-rs/wasm-runtime": "npm:^1.0.3"
"@tursodatabase/database-core": "npm:^0.1.5-pre.4" "@tursodatabase/database-core": "npm:^0.1.5-pre.3"
"@vitest/browser": "npm:^3.2.4" "@vitest/browser": "npm:^3.2.4"
playwright: "npm:^1.55.0" playwright: "npm:^1.55.0"
typescript: "npm:^5.9.2" typescript: "npm:^5.9.2"
@@ -1408,7 +1408,7 @@ __metadata:
languageName: unknown languageName: unknown
linkType: soft linkType: soft
"@tursodatabase/database-core@npm:^0.1.5-pre.4, @tursodatabase/database-core@workspace:packages/core": "@tursodatabase/database-core@npm:^0.1.5-pre.3, @tursodatabase/database-core@workspace:packages/core":
version: 0.0.0-use.local version: 0.0.0-use.local
resolution: "@tursodatabase/database-core@workspace:packages/core" resolution: "@tursodatabase/database-core@workspace:packages/core"
dependencies: dependencies:
@@ -1421,8 +1421,7 @@ __metadata:
resolution: "@tursodatabase/database@workspace:packages/native" resolution: "@tursodatabase/database@workspace:packages/native"
dependencies: dependencies:
"@napi-rs/cli": "npm:^3.1.5" "@napi-rs/cli": "npm:^3.1.5"
"@napi-rs/wasm-runtime": "npm:^1.0.3" "@tursodatabase/database-core": "npm:^0.1.5-pre.3"
"@tursodatabase/database-core": "npm:^0.1.5-pre.4"
"@types/node": "npm:^24.3.1" "@types/node": "npm:^24.3.1"
typescript: "npm:^5.9.2" typescript: "npm:^5.9.2"
vitest: "npm:^3.2.4" vitest: "npm:^3.2.4"