Skip to content

Commit 6d09418

Browse files
authored
Merge pull request #5 from gms1/feature/promise-api
promise api
2 parents 0cf28e4 + e65ae16 commit 6d09418

21 files changed

Lines changed: 3662 additions & 36 deletions

.editorconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ trim_trailing_whitespace = true
1313
insert_final_newline = true
1414

1515
# Matches multiple files with the same settings
16-
[*.js]
17-
indent_size = 2
16+
[*.js;*.ts]
17+
indent_size = 4
1818

1919
[*.json]
2020
indent_size = 2

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ local.env
2626
setup.sh
2727
/build-tmp-napi-v3
2828
/build-tmp-napi-v6
29+
/.nyc_output
2930
*.tgz
3031
package-lock.json
3132
prebuilds

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,46 @@ SQLite's [SQLCipher extension](https://github.com/sqlcipher/sqlcipher) is also
6464

6565
# API
6666

67-
See the [API documentation](https://github.com/gms1/node-sqlite3/wiki/API) in the wiki.
67+
See the [API documentation](docs/API.md) for detailed documentation of both the callback-based and Promise-based APIs.
68+
69+
## Quick Example
70+
71+
### Callback-based API (Traditional)
72+
73+
```js
74+
const sqlite3 = require('@homeofthings/sqlite3').verbose();
75+
const db = new sqlite3.Database(':memory:');
76+
77+
db.serialize(() => {
78+
db.run("CREATE TABLE lorem (info TEXT)");
79+
db.run("INSERT INTO lorem VALUES (?)", ['test']);
80+
db.each("SELECT * FROM lorem", (err, row) => {
81+
console.log(row);
82+
});
83+
});
84+
85+
db.close();
86+
```
87+
88+
### Promise-based API (Modern)
89+
90+
```js
91+
const { SqliteDatabase } = require('@homeofthings/sqlite3');
92+
93+
async function main() {
94+
const db = await SqliteDatabase.open(':memory:');
95+
96+
await db.run("CREATE TABLE lorem (info TEXT)");
97+
await db.run("INSERT INTO lorem VALUES (?)", ['test']);
98+
99+
const rows = await db.all("SELECT * FROM lorem");
100+
console.log(rows);
101+
102+
await db.close();
103+
}
104+
105+
main().catch(console.error);
106+
```
68107

69108
# Usage
70109

0 commit comments

Comments
 (0)