-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathsync.js
37 lines (29 loc) · 1004 Bytes
/
sync.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { createClient } from "@libsql/client";
import reader from "readline-sync";
async function example() {
const config = {
url: process.env.URL ?? "file:local.db",
syncUrl: process.env.SYNC_URL,
authToken: process.env.AUTH_TOKEN,
};
const db = createClient(config);
await db.sync();
await db.execute(
"CREATE TABLE IF NOT EXISTS guest_book_entries (comment TEXT)",
);
const rep = await db.sync();
console.log("frames_synced: " + rep.frames_synced);
const comment = reader.question("Enter your comment: ");
await db.execute({
sql: "INSERT INTO guest_book_entries (comment) VALUES (?)",
args: [comment],
});
const rep2 = await db.sync();
console.log("frames_synced: " + rep2.frames_synced);
console.log("Guest book entries:");
const rs = await db.execute("SELECT * FROM guest_book_entries");
for (const row of rs.rows) {
console.log(" - " + row.comment);
}
}
example();