Skip to content

Commit

Permalink
Merge pull request #275 from tursodatabase/examples
Browse files Browse the repository at this point in the history
Add examples
  • Loading branch information
notrab authored Oct 17, 2024
2 parents e9db106 + b121779 commit 5008acd
Show file tree
Hide file tree
Showing 40 changed files with 3,256 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/batch/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
local.db
19 changes: 19 additions & 0 deletions examples/batch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Batch

This example demonstrates how to use libSQL to execute a batch of SQL statements.

## Install Dependencies

```bash
npm i
```

## Running

Execute the example:

```bash
node index.mjs
```

This will setup a SQLite database, execute a batch of SQL statements, and then query the results.
28 changes: 28 additions & 0 deletions examples/batch/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { createClient } from "@libsql/client";

const client = createClient({
url: "file:local.db",
});

await client.batch(
[
"CREATE TABLE IF NOT EXISTS users (email TEXT)",
{
sql: "INSERT INTO users VALUES (?)",
args: ["[email protected]"],
},
{
sql: "INSERT INTO users VALUES (?)",
args: ["[email protected]"],
},
{
sql: "INSERT INTO users VALUES (?)",
args: ["[email protected]"],
},
],
"write",
);

const result = await client.execute("SELECT * FROM users");

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

0 comments on commit 5008acd

Please sign in to comment.