new GDB()) to the new async factory function (await gdb()). It covers key changes, before/after examples, and common pitfalls.
Key Changes
Async Initialization
Must use
await gdb(name, options) instead of new GDB()Stable API
Public operations (
put, get, map, etc.) remain unchangedInternal Access
hybridClock, graph, syncChannel exposed for module compatibilityBetter Errors
Using
new GDB() throws error with migration instructionsQuick Migration
Basic Initialization
Using map (Real-Time Subscription)
Using get (Point-in-Time and Reactive)
Write and Delete
Security Manager (SM) Integration
Recommended Initialization
The
sm object is injected when passing { sm: { superAdmins: [...] } }. Access it via db.sm.Permission Check Example
Browser Usage (ESM)
Common Pitfalls
Error: db.map is not a function
Error: db.map is not a function
Cause: Using
db before initialization completesFix:SM Error: Cannot read properties of undefined
SM Error: Cannot read properties of undefined
Cause: Module expected
db.hybridClock which was not exposed in old versionsStatus: Fixed in current version. hybridClock, graph, and syncChannel are exposed as getters.map doesn't emit after loading graph
map doesn't emit after loading graph
Cause: Not awaiting initialization or incorrect query filtersFix:
- Ensure
await gdb(...)beforedb.map(...) - Check your
queryfilter isn’t too restrictive
Migration Checklist
Full Example (To-Do List)
FAQ
Can I still use db.ready?
Can I still use db.ready?
It may exist in some contexts for legacy compatibility, but it’s not recommended. Prefer
await gdb(...).Did map or get signatures change?
Did map or get signatures change?
No. They still return
{ results, unsubscribe } or { result, unsubscribe } accordingly.How do I filter and order in map?
How do I filter and order in map?
Use options:
{ query: {...}, field: 'timestamp', order: 'asc'|'desc', $limit, $after, $before }Need help? Open an issue on GitHub with before/after code and the observed error.