Skip to content

Commit

Permalink
Add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
giovannibenussi committed Oct 16, 2024
1 parent e9db106 commit d3f4d86
Show file tree
Hide file tree
Showing 31 changed files with 2,418 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 d3f4d86

Please sign in to comment.