-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathexample.js
37 lines (33 loc) · 1 KB
/
example.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";
async function example() {
const config = {
url: process.env.URL ?? "file:local.db",
encryptionKey: process.env.ENCRYPTION_KEY,
};
const db = createClient(config);
await db.batch(
[
"CREATE TABLE IF NOT EXISTS users (email TEXT)",
"INSERT INTO users (email) VALUES ('[email protected]')",
"INSERT INTO users (email) VALUES ('[email protected]')",
],
"write",
);
await db.batch(
[
{
sql: "INSERT INTO users (email) VALUES (?)",
args: ["[email protected]"],
},
["INSERT INTO users (email) VALUES (?)", ["[email protected]"]],
{
sql: "INSERT INTO users (email) VALUES (:email)",
args: { email: "[email protected]" },
},
],
"write",
);
const rs = await db.execute("SELECT * FROM users");
console.log(rs);
}
await example();