sqlite: add serialize() and deserialize() to DatabaseSync#62579
sqlite: add serialize() and deserialize() to DatabaseSync#62579thisalihassan wants to merge 1 commit intonodejs:mainfrom
Conversation
|
Review requested:
|
Add database.serialize() and database.deserialize() methods to DatabaseSync, wrapping the sqlite3_serialize and sqlite3_deserialize C APIs. These allow extracting an in-memory database as a Uint8Array and loading one back, enabling snapshots, cloning, and transfer of databases without filesystem I/O. Refs: nodejs#62575
9b9212f to
52f29ac
Compare
| } | ||
|
|
||
| unsigned char* buf = | ||
| static_cast<unsigned char*>(sqlite3_malloc64(byte_length)); |
There was a problem hiding this comment.
sqlite3_deserialize() takes ownership of the buffer when passed SQLITE_DESERIALIZE_FREEONCLOSE
sqlite3_deserialize docs:
"If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will invoke sqlite3_free() on the serialization buffer when the database connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then SQLite will try to increase the buffer size using sqlite3_realloc64() if writes on the database cause it to grow larger than M bytes."
There was a problem hiding this comment.
A comment to that effect would be helpful.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62579 +/- ##
==========================================
- Coverage 89.71% 89.70% -0.01%
==========================================
Files 695 695
Lines 214441 214522 +81
Branches 41062 41077 +15
==========================================
+ Hits 192384 192438 +54
+ Misses 14123 14122 -1
- Partials 7934 7962 +28
🚀 New features to boost your workflow:
|
Add
serialize()and.deserialize()methods to DatabaseSync, wrapping thesqlite3_serializeandsqlite3_deserialize. These allow extracting an in-memory database as a Uint8Array and loading one back enabling snapshots, cloning, etc..Implemenation Notes:
serialize()wraps the SQLite allocated buffer directly in a V8BackingStoreto avoid copying the entire database.#ifdef V8_ENABLE_SANDBOXfalls back to a copy path since that configuration forbids external backing stores.deserialize()must copy once because SQLite requiressqlite3_malloc64allocated memory.Wrote test cases with Claude & GPT 5.4
Refs: #62575