Skip to content

Commit 45426f0

Browse files
Add plain javascript example with async call
1 parent 26def96 commit 45426f0

File tree

4 files changed

+353
-0
lines changed

4 files changed

+353
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## Getting Started
2+
3+
This example shows how to use @sqlitecloud/drivers in plain Javascript
4+
5+
To run the example:
6+
7+
```bash
8+
npm install
9+
npm run start
10+
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// Using @sqlitecloud/drivers with plain Javascript
3+
//
4+
5+
var sqlitecloud = require('@sqlitecloud/drivers')
6+
7+
require('dotenv').config()
8+
var DATABASE_URL = process.env.DATABASE_URL
9+
console.assert(DATABASE_URL, 'DATABASE_URL environment variable not set in .env')
10+
11+
async function selectTracks() {
12+
// create a connection with sqlitecloud
13+
var database = new sqlitecloud.Database(DATABASE_URL)
14+
15+
// run async query
16+
var tracks = await database.sql`USE DATABASE chinook.sqlite; SELECT * FROM tracks LIMIT 20;`
17+
console.log(`getTracks returned:`, tracks)
18+
19+
// You can also use all the regular sqlite3 api with callbacks, see:
20+
// https://docs.sqlitecloud.io/docs/sdk/js/intro
21+
}
22+
23+
void selectTracks()

examples/with-plain-javascript/package-lock.json

Lines changed: 307 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "with-javascript-express",
3+
"version": "0.0.0",
4+
"private": true,
5+
"scripts": {
6+
"start": "node ./app.js"
7+
},
8+
"dependencies": {
9+
"@sqlitecloud/drivers": "^0.0.56",
10+
"debug": "^4.3.4",
11+
"dotenv": "^16.4.5"
12+
}
13+
}

0 commit comments

Comments
 (0)