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.
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.
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.
Solves both SQL's join complexity and the ORM's N+1 problem. Infers types from the schema to prevent runtime errors.
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; } } } # 사용자 생성
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;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;
}# 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# 그래프 탐색: 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;EdgeQL is a new query language that differs from SQL. Even developers familiar with SQL have to learn a new syntax.
Compared with PostgreSQL or MongoDB, the community and third-party tools are limited. Reference material may be lacking when problems occur.
Beyond EdgeDB Cloud, managed services are limited. Self-hosting can carry an operational burden.