Move @tursodatabase/sync code to sync/javascript

This commit is contained in:
Pekka Enberg
2025-08-18 14:22:00 +03:00
parent 33ddae1877
commit 13b805a992
27 changed files with 13 additions and 13 deletions

View File

@@ -0,0 +1,33 @@
import { connect } from '@tursodatabase/sync';
const db = await connect({
path: 'local.db',
url: process.env.TURSO_URL,
authToken: process.env.TURSO_AUTH_TOKEN,
clientName: 'turso-sync-example'
});
await db.sync();
console.info("database initialized and ready to accept writes")
{
console.info("data from remote")
let stmt = await db.prepare('SELECT * FROM users');
console.info(await stmt.all());
}
for (let i = 0; i < 2; i++) {
let id = Math.ceil(Math.random() * 100000);
await db.exec(`INSERT INTO users VALUES (${id}, 'random-name-${id}')`);
}
{
console.info("data after local insert")
let stmt = await db.prepare('SELECT * FROM users');
console.info(await stmt.all());
}
console.info("sync changes with the remote")
await db.sync();