Skip to content

Commit e65ae16

Browse files
committed
memory bank
1 parent de1adc9 commit e65ae16

7 files changed

Lines changed: 271 additions & 5 deletions

File tree

memory-bank/activeContext.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Active Context
2+
3+
## Current Status
4+
5+
**Last Updated**: 2026-03-28
6+
7+
## Current Work
8+
9+
### Promisification Implementation
10+
11+
**Status**: ✅ COMPLETE
12+
13+
Promise-based wrapper classes are implemented in [`lib/promise/`](../lib/promise/):
14+
15+
- [`SqliteDatabase`](../lib/promise/database.js) - Promise wrapper for `Database`
16+
- [`SqliteStatement`](../lib/promise/statement.js) - Promise wrapper for `Statement`
17+
- [`SqliteBackup`](../lib/promise/backup.js) - Promise wrapper for `Backup`
18+
- [`index.js`](../lib/promise/index.js) - Module exports
19+
20+
**Features Implemented**:
21+
- Static factory method `SqliteDatabase.open(filename, mode)`
22+
- All async methods return Promises
23+
- Transaction support: `beginTransaction()`, `commitTransaction()`, `rollbackTransaction()`
24+
- `each()` method with row callback pattern
25+
- Event emitter support preserved
26+
27+
## Pending Tasks
28+
29+
No active tasks currently assigned.
30+
31+
## Recent Changes
32+
33+
- Memory-bank structure created with UMB workflow support
34+
- Promisification implementation verified as complete
35+
36+
## Open Questions
37+
38+
None currently.
39+
40+
## Next Steps
41+
42+
Awaiting new task assignments.

memory-bank/build-system.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ Main build configuration file:
2828
"src/statement.cc"
2929
],
3030
"defines": [
31-
"NAPI_VERSION=<(napi_build_version)",
32-
"NAPI_DISABLE_CPP_EXCEPTIONS=1"
31+
"NAPI_VERSION=<(napi_build_version)"
3332
]
3433
// ... more config
3534
}

memory-bank/custom-instructions.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# AI Agent Instructions
2+
3+
> These instructions are for AI agents (like Roo/Cline) working on this project.
4+
5+
## Command Execution
6+
7+
- Do not prefix commands with `cd /home/gms/gms/projects/hot/node-sqlite3 &&` when the command should run in the current workspace directory
8+
- Use `yarn test`, `yarn lint` instead of npm run scripts (e.g., avoid `npm run test`, use `yarn test` instead)
9+
10+
## Notes
11+
12+
These instructions apply to all future sessions working in this project.
13+
14+
## Memory Bank
15+
16+
The most important part of the Memory Bank is keeping it updated. Currently, the community standard is the UMB (Update Memory Bank) routine:
17+
18+
- Before you start a task: Ask your AI agent, "Read the memory bank and tell me the current status."
19+
20+
- While working, the AI agent will occasionally suggest updates to activeContext.md.
21+
22+
- Before you end a session: Simply type "UMB" or "Update memory bank". The AI agent will then:
23+
24+
- Move completed items from activeContext.md to progress.md.
25+
26+
- Log any new technical decisions in decisionLog.md.
27+
28+
- Clear the activeContext.md for the next session.

memory-bank/decisionLog.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Decision Log
2+
3+
## Technical Decisions
4+
5+
### 2026-03-29: NAPI Exception Handling
6+
7+
**Decision**: Use `node_addon_api_except` instead of `NAPI_DISABLE_CPP_EXCEPTIONS=1`
8+
9+
**Rationale**:
10+
- Commit 48e95e8a0d32277449c269b41fba6419acb21418 changed the build configuration
11+
- Using `node_addon_api_except` from node-addon-api provides proper exception handling support
12+
- This is the recommended approach for modern node-addon-api versions
13+
14+
**Files Changed**:
15+
- `binding.gyp`: Changed from `node_addon_api` to `node_addon_api_except` dependency
16+
17+
---
18+
19+
### 2026-03-28: Memory Bank Structure
20+
21+
**Decision**: Adopt UMB (Update Memory Bank) workflow with standard file structure.
22+
23+
**Rationale**: Following 2026 community standards for AI agent context management.
24+
25+
**Files Created**:
26+
- `activeContext.md` - Current work status
27+
- `progress.md` - Completed work history
28+
- `decisionLog.md` - Technical decisions record
29+
30+
---
31+
32+
### Promisification Architecture
33+
34+
**Decision**: Create Promise-based wrapper classes alongside callback-based classes.
35+
36+
**Status**: ✅ IMPLEMENTED
37+
38+
**Rationale**:
39+
- Maintains backward compatibility with existing callback API
40+
- Provides modern async/await support
41+
- Follows established pattern from sqlite3orm reference implementation
42+
43+
**Implementation**:
44+
- New classes: `SqliteDatabase`, `SqliteStatement`, `SqliteBackup`
45+
- Exported from `lib/promise/index.js`
46+
- Generic type parameters for TypeScript type inference
47+
- Transaction support with `beginTransaction()`, `commitTransaction()`, `rollbackTransaction()`
48+
- Static factory method `SqliteDatabase.open()`
49+
50+
**Alternatives Considered**:
51+
1. Modify existing classes to return Promises - Rejected (breaks backward compatibility)
52+
2. Create separate package - Deferred (can be refactored later if needed)
53+
54+
---
55+
56+
### Node.js Version Requirement
57+
58+
**Decision**: Require Node.js >= 20.17.0
59+
60+
**Rationale**:
61+
- Modern NAPI support
62+
- Latest performance improvements
63+
- Simplified maintenance
64+
65+
---
66+
67+
### Build System Choice
68+
69+
**Decision**: Use node-gyp with prebuild for binary distribution
70+
71+
**Rationale**:
72+
- Established tool for native addons
73+
- Prebuilt binaries reduce installation friction
74+
- Supports multiple NAPI versions (3, 6)
75+
76+
---
77+
78+
### SQLite Configuration
79+
80+
**Decision**: Bundle SQLite with enabled extensions
81+
82+
**Extensions Enabled**:
83+
- `SQLITE_THREADSAFE=1` - Thread safety
84+
- `SQLITE_ENABLE_FTS3/4/5` - Full-text search
85+
- `SQLITE_ENABLE_RTREE` - R-Tree index
86+
- `SQLITE_ENABLE_DBSTAT_VTAB=1` - Database stats
87+
- `SQLITE_ENABLE_MATH_FUNCTIONS` - Math functions
88+
89+
**Rationale**: Provides comprehensive SQLite functionality out of the box.
90+
91+
---
92+
93+
### Test Framework
94+
95+
**Decision**: Use mocha with 480s timeout
96+
97+
**Rationale**:
98+
- Established test suite
99+
- Handles async operations well
100+
- Compatible with existing tests

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/progress.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Progress Log
2+
3+
## 2026-03-29
4+
5+
### Memory Bank Update
6+
- Removed `NAPI_DISABLE_CPP_EXCEPTIONS` from documentation (commit 48e95e8a0d32277449c269b41fba6419acb21418)
7+
- Updated `build-system.md` and `project-overview.md` to reflect current binding.gyp configuration
8+
9+
## 2026-03-28
10+
11+
### Memory Bank Setup
12+
- Created UMB-compliant memory-bank structure
13+
- Added `activeContext.md` for current work tracking
14+
- Added `progress.md` for completed work history
15+
- Added `decisionLog.md` for technical decisions
16+
- Updated to reflect actual project state
17+
18+
### Promisification Implementation (VERIFIED COMPLETE)
19+
- Promise-based wrapper classes implemented in [`lib/promise/`](../lib/promise/)
20+
- `SqliteDatabase` class with full API coverage
21+
- `SqliteStatement` class with all methods
22+
- `SqliteBackup` class for backup operations
23+
- Transaction support: `beginTransaction()`, `commitTransaction()`, `rollbackTransaction()`
24+
- Static factory method `SqliteDatabase.open()`
25+
- Tests in [`test/promise.test.js`](../test/promise.test.js)
26+
27+
## Earlier Sessions
28+
29+
### Project Setup
30+
- Established Node.js >= 20.17.0 requirement
31+
- Configured yarn package manager
32+
- Set up ESLint with `.eslintrc.js`
33+
- Configured node-gyp build system
34+
35+
### Build System
36+
- Configured Debug and Release builds
37+
- Set up prebuild for binary distribution
38+
- Enabled SQLite extensions: FTS3/4/5, R-Tree, math functions
39+
40+
### Testing Infrastructure
41+
- Set up mocha test framework
42+
- Created test support utilities
43+
- Established test database creation pattern

memory-bank/project-overview.md

Lines changed: 14 additions & 2 deletions
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
@@ -65,7 +77,7 @@ node-sqlite3/
6577
- **binding.gyp**: node-gyp configuration
6678
- Builds `node_sqlite3` target
6779
- Links against SQLite (internal or external)
68-
- Defines `NAPI_VERSION` and `NAPI_DISABLE_CPP_EXCEPTIONS=1`
80+
- Defines `NAPI_VERSION` based on the target Node.js version
6981

7082
- **deps/common-sqlite.gypi**: Common build configurations
7183
- `Debug` configuration: disables `NDEBUG`, enables debug symbols

0 commit comments

Comments
 (0)