Skip to content

Commit 9089d08

Browse files
Adding usage example with Knex SQL query builder
https://knexjs.org/
1 parent 816ebd9 commit 9089d08

File tree

9 files changed

+465
-5
lines changed

9 files changed

+465
-5
lines changed

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

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/with-javascript-express/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
"dotenv": "^16.3.1",
1111
"express": "^4.18.2",
1212
"http-errors": "^2.0.0",
13-
"sqlitecloud-js": "^0.0.20-beta"
13+
"sqlitecloud-js": "^0.0.25"
1414
}
1515
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
.yarn/install-state.gz
8+
9+
# testing
10+
/coverage
11+
12+
# next.js
13+
/.next/
14+
/out/
15+
16+
# production
17+
/build
18+
19+
# misc
20+
.DS_Store
21+
*.pem
22+
23+
# debug
24+
npm-debug.log*
25+
yarn-debug.log*
26+
yarn-error.log*
27+
28+
# local env files
29+
.env*.local
30+
31+
# vercel
32+
.vercel
33+
34+
# typescript
35+
*.tsbuildinfo
36+
next-env.d.ts
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Getting Started
2+
3+
This example shows how you can use sqlitecloud-js with [Knex](https://knexjs.org/), a SQL query builder for Javascript.
4+
5+
You can launch example.ts from VS Code "Run and Debug" menu.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// Using sqlitecloud drivers with knex
3+
//
4+
5+
import { knex } from 'knex'
6+
7+
const Client_SQLite3 = require('knex/lib/dialects/sqlite3')
8+
9+
// client will have sqlite3 dialect, but will use sqlitecloud-js driver
10+
class Client_Libsql extends Client_SQLite3 {
11+
_driver() {
12+
return require('sqlitecloud-js')
13+
}
14+
}
15+
16+
console.assert(process.env.CHINOOK_DATABASE_URL, 'Define CHINOOK_URL environment variable')
17+
18+
// create knex instance with sqlitecloud-js driver
19+
// database url is passed as filename parameter
20+
const db = knex({
21+
client: Client_Libsql as any,
22+
connection: {
23+
filename: process.env.CHINOOK_DATABASE_URL as string
24+
}
25+
})
26+
27+
db.raw('select * from customers')
28+
.then(result => {
29+
console.log(`Connected to database via knex and received ${result.length} rows`)
30+
console.log(JSON.stringify(result, null, 2))
31+
db.destroy()
32+
})
33+
.catch(err => {
34+
console.error(err)
35+
db.destroy()
36+
})
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {}
3+
4+
module.exports = nextConfig

0 commit comments

Comments
 (0)