Skip to content

Commit

Permalink
Merge pull request #282 from levydsa/read_your_writes
Browse files Browse the repository at this point in the history
feat: add readYourWrites to options
  • Loading branch information
levydsa authored Nov 1, 2024
2 parents 1e77794 + 4073452 commit 2f62c71
Show file tree
Hide file tree
Showing 6 changed files with 400 additions and 0 deletions.
351 changes: 351 additions & 0 deletions examples/read-your-writes/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions examples/read-your-writes/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "read-your-writes",
"version": "1.0.0",
"main": "index.mjs",
"author": "Levy Albuquerque",
"license": "MIT",
"dependencies": {
"@libsql/client": "^0.14.0"
}
}
32 changes: 32 additions & 0 deletions examples/read-your-writes/read_your_writes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { createClient } from "@libsql/client";

const client = createClient({
url: "file:local.db",
syncUrl: process.env.TURSO_DATABASE_URL,
authToken: process.env.TURSO_AUTH_TOKEN,
readYourWrites: false,
});

await client.execute("DROP TABLE users");
await client.execute("CREATE TABLE IF NOT EXISTS users (email TEXT)");
await client.sync();

await client.execute("INSERT INTO users VALUES ('[email protected]')");
await client.execute("INSERT INTO users VALUES ('[email protected]')");
await client.execute("INSERT INTO users VALUES ('[email protected]')");

{
// No users, sinc no sync has happend since inserts
const result = await client.execute("SELECT * FROM users");

console.log("Users:", result.rows);
}

{
await client.sync();

// No users, sinc no sync has happend since inserts
const result = await client.execute("SELECT * FROM users");

console.log("Users:", result.rows);
}
Loading

0 comments on commit 2f62c71

Please sign in to comment.