Skills api-database-edgedb
Graph-relational database with EdgeQL query language, code-first schema, link-based relations, computed properties, and fully typed TypeScript query builder
git clone https://github.com/agents-inc/skills
T=$(mktemp -d) && git clone --depth=1 https://github.com/agents-inc/skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/dist/plugins/api-database-edgedb/skills/api-database-edgedb" ~/.claude/skills/agents-inc-skills-api-database-edgedb && rm -rf "$T"
dist/plugins/api-database-edgedb/skills/api-database-edgedb/SKILL.mdGel (formerly EdgeDB) Patterns
Quick Guide: Gel (formerly EdgeDB) is a graph-relational database built on PostgreSQL. Define schemas in
files using SDL with types, links, and computed properties. Use.gel+gel migration createfor schema changes. Query with EdgeQL (set-based, deeply nested shapes) or the TypeScript query builder (gel migrate,e.select). Everything in EdgeQL is a set -- empty sets need explicit casts, and operations on sets produce Cartesian products. Usee.insertvariables with access policies for row-level security. The query builder requires a running database for code generation (global).npx @gel/generate edgeql-jsNaming: EdgeDB was rebranded to Gel in February 2025. The
npm package, CLI, andedgedbextension still work via compatibility shims, but new projects should use.esdl,gel, and@gel/generatefiles..gel
<critical_requirements>
CRITICAL: Before Using This Skill
All code must follow project conventions in CLAUDE.md (kebab-case, named exports, import ordering,
, named constants)import type
(You MUST run
after every npx @gel/generate edgeql-js
-- the generated query builder is based on the database schema and becomes stale after migrations)gel migrate
(You MUST cast empty sets explicitly (
, <str>{}
) -- bare <int64>{}
is a syntax error because EdgeQL is strongly typed and cannot infer the type of an empty set){}
(You MUST understand that all EdgeQL values are sets -- operations on multi-valued expressions produce Cartesian products, not element-wise results)
(You MUST pass the transaction object
(not tx
) to ALL query client
calls inside .run()
-- using client.transaction()
inside a transaction runs queries outside the transaction)client
(You MUST NOT use volatile functions like
in schema-defined computed properties -- use datetime_current()
or datetime_of_transaction()
instead)datetime_of_statement()
</critical_requirements>
Auto-detection: Gel, gel, EdgeDB, edgedb, EdgeQL, edgeql, .gel, .esdl, dbschema, edgeql-js, createClient, e.select, e.insert, e.update, e.delete, e.params, gel migrate, gel migration, edgedb migrate, SDL schema, backlink, access policy, gel.toml, edgedb.toml
When to use:
- Defining graph-relational schemas with types, links, and computed properties
- Writing type-safe queries with EdgeQL or the TypeScript query builder
- Managing schema migrations with the built-in migration system
- Modeling complex relationships (multi links, backlinks, polymorphism)
- Implementing row-level security with access policies and globals
Key patterns covered:
- Client setup and connection (
, DSN, environment variables)createClient - Schema definition in SDL (types, properties, links, constraints, computed)
- EdgeQL query language (SELECT shapes, INSERT, UPDATE, DELETE)
- TypeScript query builder (
,e.select
,e.insert
,e.update
)e.delete - Migrations workflow (
,gel migration create
)gel migrate
When NOT to use:
- Simple key-value storage (use a dedicated key-value store)
- Projects that need raw SQL as the primary interface (Gel uses EdgeQL; Gel 6+ adds native SQL support but EdgeQL is the primary interface)
- Environments where you cannot run the Gel server (it is not an embedded database)
Detailed Resources:
- For decision frameworks and quick reference, see reference.md
Core Patterns:
- examples/core.md - Client setup, schema definition, EdgeQL basics, migration workflow
Query Builder:
- examples/query-builder.md - TypeScript query builder (e.select, e.insert, e.update, e.delete, e.params)
Advanced Schema:
- examples/advanced-schema.md - Access policies, backlinks, abstract types, polymorphism, triggers
<philosophy>
Philosophy
Gel is a graph-relational database. It combines the relational model (tables, constraints, ACID) with a graph model (links between objects, deep traversal). The core idea: relationships are first-class citizens, not join tables.
Core principles:
- Schema is the source of truth -- Define everything in
files (or.gel
for legacy projects). Migrations are auto-generated by comparing your schema files against the database state..esdl - Links over foreign keys -- Use
to connect types. Gel handles the underlying foreign keys. You never write JOIN -- you traverse links with dot notation.link - Sets everywhere -- Every value in EdgeQL is a set. A single string is a set of one element. This is the most important mental model shift from SQL.
- Shapes for projection -- SELECT returns structured, nested objects (like GraphQL responses), not flat rows. You specify the "shape" of what you want.
- Computed properties are views -- Computed properties and links are not stored; they are evaluated on every query. Use them for derived data.
- Query builder for TypeScript -- The generated query builder provides compile-time type safety. Prefer it over raw EdgeQL strings in TypeScript projects.
When to use Gel:
- Applications with complex, deeply nested relationships (social graphs, content systems, e-commerce)
- Projects that benefit from graph-style traversals without sacrificing relational integrity
- TypeScript projects that want compile-time type-safe database queries
- Teams that want automatic migration generation from schema changes
When NOT to use:
- Existing projects locked into raw PostgreSQL with extensive stored procedures
- Applications where SQL compatibility is the only acceptable query language (Gel 6+ has native SQL support, but EdgeQL is the primary interface)
- Environments that cannot run the Gel server process
<patterns>
Core Patterns
Pattern 1: Client Setup
Create a client with
createClient(). Connection details are auto-discovered from gel.toml (or edgedb.toml) or environment variables.
import { createClient } from "gel"; const client = createClient(); // auto-discovers from project config export { client };
Choose the right query method by expected cardinality:
query() for sets, querySingle() for optional single, queryRequiredSingle() when result is guaranteed, execute() for side-effect-only statements. See examples/core.md for full client setup patterns.
Pattern 2: Schema Definition (SDL)
Schemas live in
dbschema/*.gel files (or *.esdl for legacy projects). Use required for non-null, link for relationships, constraint exclusive for uniqueness, computed backlinks (.<author[is Post]) for reverse traversal.
# dbschema/default.gel module default { type User { required name: str; required email: str { constraint exclusive; }; multi posts := .<author[is Post]; # computed backlink } type Post { required title: str; required author: User; # link, not uuid! } }
Key rule: Always use
link for relationships -- never raw uuid properties. See examples/core.md for complete schema patterns with constraints, indexes, and enums.
Pattern 3: EdgeQL Queries
SELECT uses shapes for projection (like GraphQL), INSERT assigns links via subqueries, UPDATE uses
+=/-=/:= for multi link manipulation.
select User { name, email, posts: { title, status } filter .status = Status.published, } filter .email = 'alice@example.com';
See examples/core.md for SELECT/INSERT/UPDATE/DELETE patterns and parameterized queries.
Pattern 4: Migrations
Gel compares your
.gel files against the database and auto-generates migrations.
gel migration create # generate migration from schema diff (interactive) gel migrate # apply pending migrations (idempotent) npx @gel/generate edgeql-js # regenerate query builder
Never edit the database with DDL directly -- always modify
.gel files and use the migration workflow. See examples/core.md for the full workflow including gel watch --migrate for prototyping.
Pattern 5: Transactions
Pass
tx (not client) to ALL operations inside client.transaction(). Using client inside the callback runs queries outside the transaction.
await client.transaction(async (tx) => { await tx.execute(`update Account ...`); // tx, not client! });
See examples/core.md for transaction patterns and examples/query-builder.md for query builder transactions.
</patterns><red_flags>
RED FLAGS
High Priority Issues:
- Using
instead ofclient
insidetx
-- queries run outside the transaction and cannot be rolled backclient.transaction() - Forgetting to run
afternpx @gel/generate edgeql-js
-- query builder types are stale and TypeScript won't catch schema mismatchesgel migrate - Using raw
properties instead ofuuid
-- defeats Gel's graph traversal and referential integritylink - Using
in schema-defined computed properties -- volatile functions are forbidden in schema computeds; usedatetime_current()
ordatetime_of_statement()datetime_of_transaction()
Medium Priority Issues:
- Bare
for empty sets -- EdgeQL requires explicit type cast ({}
,<str>{}
) because the type cannot be inferred from an empty literal<array<int64>>[] - Using
when you mean:=
on multi links in UPDATE --+=
replaces the entire set,:=
adds to it,+=
removes from it-= - Not specifying
on UPDATE/DELETE -- without a filter, the operation applies to ALL objects of that typefilter - Editing the database with DDL directly instead of through
files + migrations -- causes schema drift between files and database.gel
Common Mistakes:
- Expecting element-wise behavior from set operations --
produces{1, 2} + {10, 20}
(Cartesian product), not{11, 21, 12, 22}{11, 22} - Forgetting that
on a single link returns an object (not an ID) -- you do not need to JOIN; just traverse withselect. - Using
and expectingselect count(MyType)
to work --querySingle
always returns exactly one value, so usecount()queryRequiredSingle - Defining a computed backlink but forgetting the type filter --
without.<author
returns all types that have an[is Post]
linkauthor
Gotchas & Edge Cases:
- Computed properties are not stored -- they are re-evaluated on every query, which can be expensive for complex expressions
on a multi link means "at least one" -- an empty set violates the constraint, which can be surprisingrequired- String concatenation uses
not++
-- the+
operator is for arithmetic only+
does NOT make a query return a singleton for cardinality purposes -- useLIMIT 1
(exclusive constraint) for the query builder to infer singleton cardinalityfilter .id = <uuid>$id- Multi links are unordered sets -- if you need ordering, add an
in your query or use an intermediate type with anorder by
propertyorder - Backlinks (
) default to.<link_name
cardinality -- usemulti
keyword explicitly if you know the relationship is one-to-onesingle - EdgeDB branches (v5+) are separate database copies, not lightweight references -- branching a large database takes time and disk space proportional to the data size
</red_flags>
<critical_reminders>
CRITICAL REMINDERS
All code must follow project conventions in CLAUDE.md (kebab-case, named exports, import ordering,
, named constants)import type
(You MUST run
after every npx @gel/generate edgeql-js
-- the generated query builder is based on the database schema and becomes stale after migrations)gel migrate
(You MUST cast empty sets explicitly (
, <str>{}
) -- bare <int64>{}
is a syntax error because EdgeQL is strongly typed and cannot infer the type of an empty set){}
(You MUST understand that all EdgeQL values are sets -- operations on multi-valued expressions produce Cartesian products, not element-wise results)
(You MUST pass the transaction object
(not tx
) to ALL query client
calls inside .run()
-- using client.transaction()
inside a transaction runs queries outside the transaction)client
(You MUST NOT use volatile functions like
in schema-defined computed properties -- use datetime_current()
or datetime_of_transaction()
instead)datetime_of_statement()
Failure to follow these rules will cause stale types, silent data bugs, or transaction isolation failures.
</critical_reminders>