Skip to content

Implement async Database API (breaking change)#7

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/implement-async-database-api
Draft

Implement async Database API (breaking change)#7
Copilot wants to merge 3 commits intomainfrom
copilot/implement-async-database-api

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 1, 2026

Converts all GraphDatabase public methods from synchronous to async-returning Promises, enabling browser WASM compatibility where synchronous file I/O is unavailable.

API Changes

Migration example

// Before (v0.x)
const db = new GraphDatabase('./graph.db');
const node = db.createNode('Job', { title: 'Engineer' });
const results = db.nodes('Job').where({ status: 'active' }).exec();

// After (v1.0)
const db = await GraphDatabase.create('./graph.db');
const node = await db.createNode('Job', { title: 'Engineer' });
const results = await db.nodes('Job').where({ status: 'active' }).exec();

src/core/Database.ts

  • Added static async create(path, options?) factory method
  • Added private _getNodeSync() helper for internal sync node lookups (avoids async chains inside CRUD methods that need to validate node existence)
  • Made async: createNode, getNode, updateNode, deleteNode, createEdge, getEdge, deleteEdge, transaction, export, import, close, mergeNode, mergeEdge, createPropertyIndex, listIndexes, dropIndex
  • traverse() and nodes() remain synchronous — they return builder objects with no I/O; traverse() still validates node existence via direct db.prepare() call
  • transaction() callback now accepts T | Promise<T>, enabling async operations inside transactions
  • Fixed pre-existing TypeScript constraint error on pattern() (Record<string, unknown>Record<string, GraphEntity>)

src/query/NodeQuery.ts

  • exec(), first(), count(), exists() → async

src/query/TraversalQuery.ts

  • toArray(), toPaths(), shortestPath(), paths(), allPaths() → async
  • Internal private helpers (getNode, getNeighbors) remain synchronous

Tests (11 files)

  • All beforeEach/afterEach and test callbacks made async
  • expect(() => ...).toThrow()await expect(...).rejects.toThrow() where needed
  • Transaction callbacks updated to async (ctx) => { ... }

Copilot AI linked an issue Apr 1, 2026 that may be closed by this pull request
9 tasks
Copilot AI and others added 2 commits April 1, 2026 18:31
- Add await to all async DB methods: createNode, getNode, updateNode,
  deleteNode, createEdge, getEdge, deleteEdge, export, import, close,
  mergeNode, mergeEdge, createPropertyIndex, listIndexes, dropIndex
- Make transaction callbacks async with await on inner calls
- Await NodeQuery terminal methods: exec(), first(), count(), exists()
- Await TraversalQuery terminal methods: toArray(), toPaths(), etc.
- Make beforeEach/afterEach/it() callbacks async where needed
- Transform expect(() => asyncMethod()).toThrow() to rejects.toThrow()
- Handle Array.from/map with async callbacks using Promise.all
- Convert forEach(async ...) to await Promise.all(arr.map(async ...))
- PatternQuery.exec/first/count remain synchronous (no await)
- traverse() sync validation unchanged

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: michaeloboyle <61171+michaeloboyle@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement async Database API for browser compatibility Implement async Database API (breaking change) Apr 1, 2026
Copilot AI requested a review from michaeloboyle April 1, 2026 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement async Database API (breaking change)

2 participants