feat(extensions): Add Apache AGE graph database extension #860
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Add support for Apache AGE (A Graph Extension), bringing graph database capabilities and the Cypher query language to PGlite.
What is AGE?
Apache AGE is a PostgreSQL extension that adds:
Usage
import { PGlite } from '@electric-sql/pglite'
import { age } from '@electric-sql/pglite/age'
const pg = new PGlite({ extensions: { age } })
// Create a graph
await pg.exec("SELECT ag_catalog.create_graph('social');")
// Create nodes and relationships
await pg.exec(
SELECT * FROM ag_catalog.cypher('social', $$ CREATE (alice:Person {name: 'Alice'})-[:KNOWS]->(bob:Person {name: 'Bob'}) RETURN alice, bob $$) as (alice ag_catalog.agtype, bob ag_catalog.agtype);)// Query the graph
const result = await pg.query(
SELECT * FROM ag_catalog.cypher('social', $$ MATCH (p:Person)-[:KNOWS]->(friend:Person) RETURN p.name, friend.name $$) as (person ag_catalog.agtype, friend ag_catalog.agtype);)## ChangesNew Files
packages/pglite/src/age/index.tspackages/pglite/tests/age.test.tsdocs/extensions/age.mdModified Files
packages/pglite/package.json./ageexportpackages/pglite/tsup.config.tssrc/age/index.tsentry pointpackages/pglite/scripts/bundle-wasm.tsTechnical Details
Extension Initialization
The wrapper handles:
CREATE EXTENSION IF NOT EXISTS ageLOAD 'age'(activates Cypher parser hooks)SET search_path(includesag_catalogfor operator class resolution)32-bit WASM Compatibility
AGE required patches for PGlite's 32-bit WASM environment. The
postgres-pglitePR includes AGE as a submodule from a fork with these patches.Documentation
Full documentation added at
docs/extensions/age.md:Limitations
load_labels_from_file()not available (no filesystem in WASM)Related PRs
Checklist
pnpm test)pnpm test:web)