mirror of
https://github.com/allankoechke/turso.git
synced 2026-11-30 11:12:58 +00:00
bootstrap_db and open_db log the sync options with {:?}, and the derived
Debug printed the base64 remote encryption key into the sync logs.
Add a Secret wrapper in the sync engine whose Debug output is always
"<redacted>" and whose value is only reachable through expose(). The
options, the sync operation context and the lazy storage all keep the key
as a Secret, so any struct that holds it can keep deriving Debug without
leaking it. The only expose() call is where the HTTP request header is
built.
Tests: opts_debug_output_hides_the_remote_encryption_key in sync/engine
Turso Sync for JavaScript
About
This package is for syncing local Turso databases to the Turso Cloud and back.
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.
Installation
npm install @tursodatabase/sync
Getting Started
To sync a database hosted at Turso Cloud:
import { connect } from '@tursodatabase/sync';
const db = await connect({
path: 'local.db', // path used as a prefix for local files created by sync-engine
url: 'https://<db>.turso.io', // URL of the remote database: turso db show <db>
authToken: '...', // auth token issued from the Turso Cloud: turso db tokens create <db>
clientName: 'turso-sync-example' // arbitrary client name
});
// db has same functions as Database class from @tursodatabase/database package but adds few more methods for sync:
await db.pull(); // pull changes from the remote
await db.push(); // push changes to the remote
await db.sync(); // pull & push changes
Related Packages
- The @tursodatabase/database package provides the Turso in-memory database, compatible with SQLite.
- The @tursodatabase/serverless package provides a serverless driver with the same API.
License
This project is licensed under the MIT license.