mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-25 20:14:21 +01:00
Move @tursodatabase/sync code to sync/javascript
This commit is contained in:
33
sync/javascript/examples/cloud/example.js
Normal file
33
sync/javascript/examples/cloud/example.js
Normal 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();
|
||||
39
sync/javascript/examples/cloud/package-lock.json
generated
Normal file
39
sync/javascript/examples/cloud/package-lock.json
generated
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "cloud",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "cloud",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@tursodatabase/sync": "../.."
|
||||
}
|
||||
},
|
||||
"../..": {
|
||||
"name": "@tursodatabase/sync",
|
||||
"version": "0.1.4-pre.2",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@tursodatabase/turso": "file:../../bindings/javascript"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@napi-rs/cli": "^3.0.4",
|
||||
"@napi-rs/wasm-runtime": "^1.0.1",
|
||||
"@types/node": "^24.2.0",
|
||||
"ava": "^6.0.1",
|
||||
"tsc": "^2.0.4",
|
||||
"typescript": "^5.9.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tursodatabase/sync": {
|
||||
"resolved": "../..",
|
||||
"link": true
|
||||
}
|
||||
}
|
||||
}
|
||||
15
sync/javascript/examples/cloud/package.json
Normal file
15
sync/javascript/examples/cloud/package.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "cloud",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"description": "",
|
||||
"dependencies": {
|
||||
"@tursodatabase/sync": "../.."
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user