Skip to content

Commit 7b6cbb7

Browse files
committed
documentaton
1 parent de1adc9 commit 7b6cbb7

2 files changed

Lines changed: 56 additions & 2 deletions

File tree

memory-bank/development.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ test/
7575
├── unicode.test.js # Unicode handling tests
7676
├── update_hook.test.js # Update hook tests
7777
├── upsert.test.js # UPSERT tests
78-
└── verbose.test.js # Verbose mode tests
78+
├── verbose.test.js # Verbose mode tests
79+
└── promise.test.js # Promise API tests
7980
```
8081

8182
### Running Specific Tests
@@ -138,6 +139,47 @@ db.on('profile', (sql, time) => {
138139
});
139140
```
140141

142+
## Promise API
143+
144+
The project includes Promise-based wrappers for modern async/await support:
145+
146+
### Using Promise API
147+
148+
```javascript
149+
const { SqliteDatabase } = require('@homeofthings/sqlite3/promise');
150+
151+
// Static factory method
152+
const db = await SqliteDatabase.open(':memory:');
153+
154+
// Run queries
155+
const result = await db.run('CREATE TABLE foo (id INT, name TEXT)');
156+
const row = await db.get('SELECT * FROM foo WHERE id = ?', [1]);
157+
const rows = await db.all('SELECT * FROM foo');
158+
159+
// Transactions
160+
await db.beginTransaction();
161+
await db.run('INSERT INTO foo VALUES (1, "test")');
162+
await db.commitTransaction();
163+
164+
// Prepared statements
165+
const stmt = await db.prepare('INSERT INTO foo VALUES (?, ?)');
166+
await stmt.run(1, 'test');
167+
await stmt.finalize();
168+
169+
// Close
170+
await db.close();
171+
```
172+
173+
### Promise Classes
174+
175+
| Class | Description |
176+
|-------------------|---------------------------------|
177+
| `SqliteDatabase` | Promise wrapper for `Database` |
178+
| `SqliteStatement` | Promise wrapper for `Statement` |
179+
| `SqliteBackup` | Promise wrapper for `Backup` |
180+
181+
See [`lib/promise/`](../lib/promise/) for implementation details.
182+
141183
## Code Style
142184

143185
### Linting

memory-bank/project-overview.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ node-sqlite3/
1818
│ ├── sqlite3.js # Main module entry point
1919
│ ├── sqlite3-binding.js # Native binding loader
2020
│ ├── sqlite3.d.ts # TypeScript declarations
21-
│ └── trace.js # Stack trace augmentation for verbose mode
21+
│ ├── trace.js # Stack trace augmentation for verbose mode
22+
│ └── promise/ # Promise-based API wrappers
23+
│ ├── index.js # Promise module exports
24+
│ ├── database.js # SqliteDatabase class
25+
│ ├── statement.js # SqliteStatement class
26+
│ └── backup.js # SqliteBackup class
2227
├── src/ # C++ native addon
2328
│ ├── node_sqlite3.cc # Main addon entry
2429
│ ├── database.cc/h # Database class
@@ -52,6 +57,13 @@ node-sqlite3/
5257
- **trace.js**: Stack trace augmentation for verbose mode
5358
- Extends error stack traces to include operation context
5459

60+
- **promise/**: Promise-based API wrappers (modern async/await support)
61+
- `SqliteDatabase` class: `open()`, `close()`, `run()`, `get()`, `all()`, `each()`, `exec()`, `prepare()`, `backup()`
62+
- `SqliteStatement` class: `bind()`, `reset()`, `finalize()`, `run()`, `get()`, `all()`, `each()`
63+
- `SqliteBackup` class: `step()`, `finish()`
64+
- Transaction support: `beginTransaction()`, `commitTransaction()`, `rollbackTransaction()`
65+
- Static factory: `SqliteDatabase.open(filename, mode)`
66+
5567
### Native Layer (src/)
5668

5769
- **node_sqlite3.cc**: Module initialization, exports `Database`, `Statement`, `Backup` classes

0 commit comments

Comments
 (0)