Skip to content

Commit 5008acd

Browse files
authored
Merge pull request #275 from tursodatabase/examples
Add examples
2 parents e9db106 + b121779 commit 5008acd

40 files changed

+3256
-0
lines changed

examples/batch/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
local.db

examples/batch/README.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Batch
2+
3+
This example demonstrates how to use libSQL to execute a batch of SQL statements.
4+
5+
## Install Dependencies
6+
7+
```bash
8+
npm i
9+
```
10+
11+
## Running
12+
13+
Execute the example:
14+
15+
```bash
16+
node index.mjs
17+
```
18+
19+
This will setup a SQLite database, execute a batch of SQL statements, and then query the results.

examples/batch/index.mjs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { createClient } from "@libsql/client";
2+
3+
const client = createClient({
4+
url: "file:local.db",
5+
});
6+
7+
await client.batch(
8+
[
9+
"CREATE TABLE IF NOT EXISTS users (email TEXT)",
10+
{
11+
sql: "INSERT INTO users VALUES (?)",
12+
args: ["[email protected]"],
13+
},
14+
{
15+
sql: "INSERT INTO users VALUES (?)",
16+
args: ["[email protected]"],
17+
},
18+
{
19+
sql: "INSERT INTO users VALUES (?)",
20+
args: ["[email protected]"],
21+
},
22+
],
23+
"write",
24+
);
25+
26+
const result = await client.execute("SELECT * FROM users");
27+
28+
console.log("Users:", result.rows);

0 commit comments

Comments
 (0)