Back to Turso

README

bindings/javascript/sync/README.md

0.7.22.5 KB
Original Source
<p align="center"> <h1 align="center">Turso Sync for JavaScript</h1> </p> <p align="center"> <a title="JavaScript" target="_blank" href="https://www.npmjs.com/package/@tursodatabase/sync"></a> <a title="MIT" target="_blank" href="https://github.com/tursodatabase/turso/blob/main/LICENSE.md"></a> </p> <p align="center"> <a title="Users Discord" target="_blank" href="https://tur.so/discord"></a> </p>

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

bash
npm install @tursodatabase/sync

Getting Started

To sync a database hosted at Turso Cloud:

js
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

License

This project is licensed under the MIT license.

Support