mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-17 08:34:19 +01:00
move examples to the top-level directory
This commit is contained in:
12
examples/javascript/database-node/README.md
Normal file
12
examples/javascript/database-node/README.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# database-node
|
||||
|
||||
This is a minimal example showing how to use [`@tursodatabase/database`](https://www.npmjs.com/package/@tursodatabase/database) in the node.js
|
||||
|
||||
---
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
npm install
|
||||
node index.mjs
|
||||
```
|
||||
21
examples/javascript/database-node/index.mjs
Normal file
21
examples/javascript/database-node/index.mjs
Normal file
@@ -0,0 +1,21 @@
|
||||
import { connect } from "@tursodatabase/database";
|
||||
|
||||
const db = await connect("local.db", {
|
||||
timeout: 1000, // busy timeout for handling high-concurrency write cases
|
||||
});
|
||||
|
||||
// execute multiple SQL statements with exec(...)
|
||||
await db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS guestbook (comment TEXT, created_at DEFAULT (unixepoch()));
|
||||
CREATE INDEX IF NOT EXISTS guestbook_idx ON guestbook (created_at);
|
||||
`);
|
||||
|
||||
// use prepared statements and bind args to placeholders later
|
||||
const insert = db.prepare(`INSERT INTO guestbook(comment) VALUES (?)`);
|
||||
|
||||
// use run(...) method if query only need to be executed till completion
|
||||
await insert.run([`hello, turso at ${Math.floor(Date.now() / 1000)}`]);
|
||||
|
||||
const select = db.prepare(`SELECT * FROM guestbook ORDER BY created_at DESC LIMIT ?`);
|
||||
// use all(...) or get(...) methods to get all or one row from the query
|
||||
console.info(await select.all([5]))
|
||||
40
examples/javascript/database-node/package-lock.json
generated
Normal file
40
examples/javascript/database-node/package-lock.json
generated
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "database-node",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "database-node",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@tursodatabase/database": "../../../bindings/javascript/packages/native"
|
||||
}
|
||||
},
|
||||
"../../../bindings/javascript/packages/database": {
|
||||
"extraneous": true
|
||||
},
|
||||
"../../../bindings/javascript/packages/native": {
|
||||
"name": "@tursodatabase/database",
|
||||
"version": "0.2.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@tursodatabase/database-common": "^0.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@napi-rs/cli": "^3.1.5",
|
||||
"@types/node": "^24.3.1",
|
||||
"better-sqlite3": "^12.2.0",
|
||||
"drizzle-kit": "^0.31.4",
|
||||
"drizzle-orm": "^0.44.5",
|
||||
"typescript": "^5.9.2",
|
||||
"vitest": "^3.2.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@tursodatabase/database": {
|
||||
"resolved": "../../../bindings/javascript/packages/native",
|
||||
"link": true
|
||||
}
|
||||
}
|
||||
}
|
||||
16
examples/javascript/database-node/package.json
Normal file
16
examples/javascript/database-node/package.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "database-node",
|
||||
"version": "1.0.0",
|
||||
"main": "index.mjs",
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"description": "",
|
||||
"scripts": {
|
||||
"tsc-build": "echo 'no tsc-build'",
|
||||
"build": "echo 'no build'",
|
||||
"test": "echo 'no tests'"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tursodatabase/database": "../../../bindings/javascript/packages/native"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user