Skip to content

Commit 62c90dc

Browse files
Update example/with-typescript-knex #64
1 parent 85f6e50 commit 62c90dc

File tree

6 files changed

+245
-57
lines changed

6 files changed

+245
-57
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# connection string for your database node on sqlitecloud.io
2+
DATABASE_URL="sqlitecloud://user:password@host.sqlite.cloud:8860"
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## Getting Started
22

3-
This example shows how you can use sqlitecloud-js with [Knex](https://knexjs.org/), a SQL query builder for Javascript.
3+
This example shows how you can use @sqlitecloud/drivers with [Knex](https://knexjs.org/), a SQL query builder for Javascript.
44

5-
You can launch example.ts from VS Code "Run and Debug" menu.
5+
You can launch example.ts from VS Code "Run and Debug" menu which will launch node.
6+
7+
You can also use this example to try @sqlitecloud/drivers using bun:
8+
9+
```
10+
bun example.ts
11+
```

examples/with-typescript-knex/example.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Using sqlitecloud drivers with knex
2+
// Using @sqlitecloud/drivers with Typescript and Knex
33
//
44

55
import { knex } from 'knex'
@@ -9,22 +9,22 @@ const Client_SQLite3 = require('knex/lib/dialects/sqlite3')
99
// client will have sqlite3 dialect, but will use sqlitecloud-js driver
1010
class Client_Libsql extends Client_SQLite3 {
1111
_driver() {
12-
return require('sqlitecloud-js')
12+
return require('@sqlitecloud/drivers')
1313
}
1414
}
1515

16-
console.assert(process.env.CHINOOK_DATABASE_URL, 'Define CHINOOK_URL environment variable')
16+
console.assert(process.env.DATABASE_URL, 'Define DATABASE_URL environment variable')
1717

1818
// create knex instance with sqlitecloud-js driver
1919
// database url is passed as filename parameter
2020
const db = knex({
2121
client: Client_Libsql as any,
2222
connection: {
23-
filename: process.env.CHINOOK_DATABASE_URL as string
23+
filename: process.env.DATABASE_URL as string
2424
}
2525
})
2626

27-
db.raw('select * from customers')
27+
db.raw('USE DATABASE chinook.sqlite; SELECT * FROM customers')
2828
.then(result => {
2929
console.log(`Connected to database via knex and received ${result.length} rows`)
3030
console.log(JSON.stringify(result, null, 2))

examples/with-typescript-knex/package-lock.json

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

0 commit comments

Comments
 (0)