Skip to content

Commit e8a03a3

Browse files
committed
improved documentation
1 parent 08ed986 commit e8a03a3

File tree

5 files changed

+628
-0
lines changed

5 files changed

+628
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ package-lock.json
3131
prebuilds
3232
.vscode
3333
.clinerules
34+
.roomodes

docs/DEVELOP.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,23 @@ When you push a tag (e.g., `v6.0.2`), the CI workflow will:
5252
After releasing, you can verify:
5353
- GitHub Release with binaries: https://github.com/gms1/node-sqlite3/releases
5454
- npm package: https://www.npmjs.com/package/@homeofthings/sqlite3
55+
56+
## Code Quality
57+
58+
**IMPORTANT**: After making any code changes, always run:
59+
```bash
60+
yarn lint --fix
61+
yarn test
62+
```
63+
64+
This ensures:
65+
- Code follows project style guidelines
66+
- No syntax errors are introduced
67+
- All tests pass before committing
68+
69+
### Pre-commit Checklist
70+
71+
Before committing changes:
72+
1. Run `yarn lint --fix` to fix code style issues
73+
2. Run `yarn test` to ensure all tests pass
74+
3. Review changes before pushing

memory-bank/build-system.md

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
# Build System
2+
3+
## Overview
4+
5+
The project uses **node-gyp** to build the native SQLite3 addon. The build system supports both Debug and Release configurations.
6+
7+
## Build Files
8+
9+
### binding.gyp
10+
11+
Main build configuration file:
12+
13+
```python
14+
{
15+
"includes": ["deps/common-sqlite.gypi"],
16+
"variables": {
17+
"sqlite%": "internal", # Use bundled SQLite
18+
"sqlite_libname%": "sqlite3",
19+
"module_name": "node_sqlite3",
20+
},
21+
"targets": [
22+
{
23+
"target_name": "<(module_name)",
24+
"sources": [
25+
"src/backup.cc",
26+
"src/database.cc",
27+
"src/node_sqlite3.cc",
28+
"src/statement.cc"
29+
],
30+
"defines": [
31+
"NAPI_VERSION=<(napi_build_version)",
32+
"NAPI_DISABLE_CPP_EXCEPTIONS=1"
33+
]
34+
// ... more config
35+
}
36+
]
37+
}
38+
```
39+
40+
### deps/common-sqlite.gypi
41+
42+
Common build configurations:
43+
44+
| Configuration | Defines | Optimization |
45+
|--------------|---------|--------------|
46+
| Debug | `DEBUG`, `_DEBUG` | None (`-O0`) |
47+
| Release | `NDEBUG` | Full (`-O3`) |
48+
49+
### deps/sqlite3.gyp
50+
51+
SQLite library build configuration:
52+
- Compiles SQLite from source tarball
53+
- Enables FTS3/4/5, R-Tree, math functions
54+
- Thread-safe configuration
55+
56+
## Build Commands
57+
58+
### Standard Build
59+
60+
```bash
61+
# Install with prebuild or compile
62+
yarn install
63+
64+
# Explicit rebuild
65+
yarn rebuild
66+
# or
67+
node-gyp rebuild
68+
```
69+
70+
Output: `build/Release/node_sqlite3.node`
71+
72+
### Debug Build
73+
74+
```bash
75+
node-gyp rebuild --debug
76+
```
77+
78+
Output: `build/Debug/node_sqlite3.node`
79+
80+
### Clean Build
81+
82+
```bash
83+
node-gyp clean
84+
node-gyp rebuild
85+
```
86+
87+
### Verbose Build
88+
89+
```bash
90+
node-gyp rebuild --verbose
91+
```
92+
93+
## Build Configurations
94+
95+
### Debug Configuration
96+
97+
Enables:
98+
- `DEBUG` and `_DEBUG` preprocessor macros
99+
- Debug symbols (`GCC_GENERATE_DEBUGGING_SYMBOLS: YES`)
100+
- No optimizations (`GCC_OPTIMIZATION_LEVEL: 0`)
101+
- `ASSERT_STATUS()` macro checks (src/macros.h:140)
102+
103+
### Release Configuration (Default)
104+
105+
Enables:
106+
- `NDEBUG` preprocessor macro
107+
- Full optimizations (`GCC_OPTIMIZATION_LEVEL: 3`)
108+
- No debug symbols
109+
110+
## Custom Build Options
111+
112+
### Using External SQLite
113+
114+
```bash
115+
node-gyp rebuild --sqlite=/path/to/sqlite --sqlite_libname=sqlite3
116+
```
117+
118+
### Specifying NAPI Version
119+
120+
Prebuilt binaries are available for NAPI versions 3 and 6 (see `package.json` binary.napi_versions).
121+
122+
## Assert Control
123+
124+
### Asserts in Debug Mode
125+
126+
The `ASSERT_STATUS` macro in src/macros.h is enabled when `DEBUG` is defined:
127+
128+
```c
129+
#ifdef DEBUG
130+
#define ASSERT_STATUS() assert(status == 0);
131+
#else
132+
#define ASSERT_STATUS() (void)status;
133+
#endif
134+
```
135+
136+
## Module Loading
137+
138+
The native addon is loaded via lib/sqlite3-binding.js:
139+
140+
```javascript
141+
module.exports = require('bindings')('node_sqlite3.node');
142+
```
143+
144+
The `bindings` package searches:
145+
1. `build/Debug/node_sqlite3.node`
146+
2. `build/Release/node_sqlite3.node`
147+
148+
**Note**: Debug builds take precedence if both exist.
149+
150+
## Prebuilt Binaries
151+
152+
### Downloading Prebuilts
153+
154+
```bash
155+
yarn install # Automatically downloads prebuilt if available
156+
```
157+
158+
### Building Prebuilts
159+
160+
```bash
161+
yarn prebuild # Build for all NAPI versions
162+
```
163+
164+
### Uploading Prebuilts
165+
166+
```bash
167+
yarn upload # Upload to GitHub releases
168+
```
169+
170+
## Platform Support
171+
172+
- Node.js >= 20.17.0
173+
- NAPI versions: 3, 6
174+
- Platforms: Linux, macOS, Windows (see prebuild configuration)
175+
176+
## Troubleshooting
177+
178+
### Build Fails
179+
180+
1. Check Node.js version: `node --version` (must be >= 20.17.0)
181+
2. Check node-gyp version: `node-gyp --version`
182+
3. Try clean rebuild: `node-gyp clean && node-gyp rebuild`
183+
4. Check Python version (node-gyp requires Python 3)
184+
185+
### Native Module Not Found
186+
187+
1. Verify build output exists: `ls build/Release/node_sqlite3.node`
188+
2. Check if bindings package is installed: `yarn install`
189+
3. Try explicit rebuild: `yarn rebuild`
190+
191+
### Debug Symbols Missing
192+
193+
1. Build with `--debug` flag: `node-gyp rebuild --debug`
194+
2. Verify output location: `build/Debug/node_sqlite3.node`
195+
196+
## Related Files
197+
198+
- [Project Overview](project-overview.md) - Architecture and components
199+
- [Development Workflow](development.md) - Testing and contributing

0 commit comments

Comments
 (0)