🗄️ Databases

EdgeDB

Graph-Relational Database

A next-generation graph-relational database built on PostgreSQL. Simplifies complex data modeling and provides complete type safety through a powerful type system and the EdgeQL query language.

📖 Detailed Explanation

EdgeDB is an open-source database built on top of PostgreSQL, designed to solve the complexity of SQL and let you write type-safe queries without an ORM. It supports object-oriented schema definitions and graph-style relationship traversal, and provides full type inference in TypeScript, Python, Go, and more.

Core philosophy: "The expressiveness of SQL + the convenience of an ORM"

Solves both SQL's join complexity and the ORM's N+1 problem. Infers types from the schema to prevent runtime errors.

EdgeDB core features

🔷
EdgeQL
Intuitive query language
📝
SDL Schema
Declarative schema definition
🔒
Type Safety
Full type inference
🐘
PostgreSQL-based
Proven stability
🔄
Migrations
Built-in migration tool
🌐
EdgeDB Cloud
Managed cloud service

💻 Code Example

1. Schema definition (SDL)

dbschema/default.esdl
module default { # User type type User { required property email -> str { constraint exclusive; # Unique constraint } required property name -> str; property created_at -> datetime { default := datetime_current(); } # Relation (reverse auto-generated) multi link posts := . str; property content -> str; required property published -> bool { default := false; } property created_at -> datetime { default := datetime_current(); } # Relation definition required link author -> User; multi link tags -> Tag; multi link comments := . str; property created_at -> datetime { default := datetime_current(); } required link post -> Post; required link author -> User; } # Tag type type Tag { required property name -> str { constraint exclusive; } } }

2. Basic EdgeQL queries

EdgeQL
# 사용자 생성 INSERT User { email := 'john@example.com', name := 'John Doe' }; # 게시글 생성 (관계 포함) INSERT Post { title := 'Getting Started with EdgeDB', content := 'EdgeDB is a next-generation database...', author := (SELECT User FILTER .email = 'john@example.com'), tags := { (INSERT Tag { name := 'database' } UNLESS CONFLICT ON .name ELSE Tag), (INSERT Tag { name := 'tutorial' } UNLESS CONFLICT ON .name ELSE Tag) } }; # 중첩 데이터 조회 (JOIN 없이!) SELECT Post { title, content, created_at, author: { name, email }, tags: { name }, comments: { content, author: { name } } ORDER BY .created_at DESC } FILTER .published = true ORDER BY .created_at DESC LIMIT 10; # 조건부 필터링 SELECT User { name, email, post_count := count(.posts), recent_post := ( SELECT .posts { title, created_at } ORDER BY .created_at DESC LIMIT 1 ) } FILTER count(.posts) > 5;

3. TypeScript client (types auto-generated)

TypeScript
import { createClient } from 'edgedb'; import e from './dbschema/edgeql-js'; // 자동 생성된 타입 const client = createClient(); // 완전한 타입 추론! async function getPublishedPosts() { const posts = await e.select(e.Post, (post) => ({ id: true, title: true, content: true, created_at: true, author: { name: true, email: true, }, tags: { name: true, }, filter: e.op(post.published, '=', true), order_by: { expression: post.created_at, direction: e.DESC, }, limit: 10, })).run(client); // posts는 완전히 타입 추론됨! // posts[0].author.name - 타입 안전 return posts; } // INSERT도 타입 안전 async function createUser(email: string, name: string) { const user = await e.insert(e.User, { email, name, }).run(client); return user; } // 복잡한 쿼리도 타입 추론 async function getUserStats(userId: string) { const result = await e.select(e.User, (user) => ({ name: true, post_count: e.count(user.posts), comment_count: e.count(user.comments), latest_post: e.select(user.posts, (post) => ({ title: true, order_by: { expression: post.created_at, direction: e.DESC }, limit: 1, })), filter_single: e.op(user.id, '=', e.uuid(userId)), })).run(client); return result; }

4. Migration

CLI commands
# Initialize EdgeDB project edgedb project init # Create migration after schema change edgedb migration create # Apply migration edgedb migrate # Check migration status edgedb migration status # Regenerate TypeScript types npx @edgedb/generate edgeql-js # Test queries in the REPL edgedb edgedb> SELECT User { name, email }; edgedb> \q

5. Advanced query patterns

EdgeQL
# 그래프 탐색: 2단계 관계 SELECT User { name, # 내 게시글에 댓글 단 사람들 commenters := ( SELECT .posts.comments.author { name, email } ) } FILTER .name = 'John'; # 집계 및 그룹화 SELECT ( GROUP Post { title, author: { name } } BY .author ) { key: { author_name := .key.author.name }, post_count := count(.elements), titles := .elements.title }; # 재귀 쿼리 (계층 구조) # 예: 카테고리의 모든 하위 카테고리 WITH MODULE default SELECT Category { name, children: { name, children: { name } } } FILTER NOT EXISTS .parent; # 전체 텍스트 검색 (fts 모듈) SELECT Post { title, content, score := fts::score(Post) } FILTER fts::search(Post, 'edgedb tutorial') ORDER BY fts::score(Post) DESC;

💬 Real-world conversation examples

Full-stack developer
"EdgeQL queries return JSON-shaped results, so you don't need JOIN to fetch nested data. It also solves the N+1 problem for you."
TypeScript developer
"With edgeql-js, types are auto-generated from the schema, so a typo or an access to a wrong field gives a compile error. Its type inference is more accurate than Prisma's."
Backend developer
"Migrations are built in, so you don't need a separate tool when changing the schema. It detects changes automatically and creates the migration files for you."
Senior developer
"It runs on PostgreSQL, so its stability is proven. However, the ecosystem is still small, so there's a bit of a lack of reference material for special cases."

⚠️ Cautions

Learning curve

EdgeQL is a new query language that differs from SQL. Even developers familiar with SQL have to learn a new syntax.

Ecosystem size

Compared with PostgreSQL or MongoDB, the community and third-party tools are limited. Reference material may be lacking when problems occur.

Hosting options

Beyond EdgeDB Cloud, managed services are limited. Self-hosting can carry an operational burden.

🔗 Related Terms

📚 Learn More