You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/internal/architecture.md
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
-
# Why We Had to Reimplement Node.js's SQLite Code
1
+
# Why we had to reimplement Node.js's SQLite code
2
2
3
3
This document explains why we couldn't directly use Node.js's C++ SQLite implementation and instead had to create a compatibility layer.
4
4
5
-
## The Core Problem: Node.js Internals
5
+
## The core problem: Node.js internals
6
6
7
7
Node.js's SQLite implementation (`node_sqlite.cc`) is deeply integrated with Node.js internals that are not accessible to addon developers. These internals include:
8
8
9
-
### 1. BaseObject Class Hierarchy
9
+
### 1. BaseObject class hierarchy
10
10
11
11
```cpp
12
12
// Node.js internal code
@@ -19,7 +19,7 @@ class DatabaseSync : public BaseObject {
19
19
- Provides automatic memory management and handle wrapping
Copy file name to clipboardExpand all lines: doc/internal/async-design.md
+28-28Lines changed: 28 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
-
# Async API Design Analysis for @photostructure/sqlite
1
+
# Async API design analysis for @photostructure/sqlite
2
2
3
3
## Summary
4
4
5
5
This document analyzes options for adding asynchronous API support to @photostructure/sqlite (currently sync-only, matching Node.js's built-in sqlite module). We recommend a separate package for the async API rather than integrating it into the existing library.
6
6
7
-
## Current State
7
+
## Current state
8
8
9
-
### What We Have
9
+
### What we have
10
10
11
11
The @photostructure/sqlite library provides:
12
12
@@ -16,15 +16,15 @@ The @photostructure/sqlite library provides:
16
16
-**Full SQLite functionality** including user-defined functions, aggregates, and more
17
17
-**Cross-platform support** with prebuilds for major platforms
18
18
19
-
### Technical Foundation
19
+
### Technical foundation
20
20
21
21
The library is built on:
22
22
23
23
-**SQLite amalgamation** (sqlite3.c) compiled directly into the addon
24
24
-**Node-addon-api** for C++ to JavaScript bindings
25
25
-**Synchronous execution model** where all operations block the JavaScript thread
26
26
27
-
## The Challenge
27
+
## The challenge
28
28
29
29
SQLite's C API is fundamentally synchronous. Operations like `sqlite3_step()`, `sqlite3_exec()`, and `sqlite3_prepare()` block until completion. To provide an async API, we need to:
30
30
@@ -33,9 +33,9 @@ SQLite's C API is fundamentally synchronous. Operations like `sqlite3_step()`, `
33
33
3. Handle concurrent access safely
34
34
4. Maintain proper connection lifecycle
35
35
36
-
## Design Options Analysis
36
+
## Design options analysis
37
37
38
-
### Option 1: Integrated Async API in Existing Library
38
+
### Option 1: integrated async API in existing library
39
39
40
40
Add async classes alongside sync classes in the same package:
@@ -282,7 +282,7 @@ const stmt = await db.prepare("SELECT * FROM users WHERE id = ?");
282
282
const user =awaitstmt.get(userId);
283
283
```
284
284
285
-
## Open Questions
285
+
## Open questions
286
286
287
287
1.**Package naming**: `@photostructure/sqlite-async` or `@photostructure/async-sqlite`?
288
288
2.**API style**: Mirror better-sqlite3's async API or create our own?
@@ -293,7 +293,7 @@ const user = await stmt.get(userId);
293
293
294
294
A separate async package is the recommended approach. It follows Node.js's own design philosophy and avoids any risk to existing sync users. The AsyncWorker pattern from node-addon-api is the right building block.
0 commit comments