-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #275 from tursodatabase/examples
Add examples
- Loading branch information
Showing
40 changed files
with
3,256 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
local.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.