EdgeQL is a spiritual successor to SQL designed with a few core principles in mind.
A jaw-dropping amount of effort has been spent attempting to bridge the gap between the relational paradigm of SQL and high-level type systems of modern programming languages. EdgeDB sidesteps this problem by modeling data in an object-relational way.
Unlike SQL, EdgeQL's syntax is readily composable; queries can be cleanly nested to perform subqueries or nested mutations.
EdgeQL is inextricably tied to EdgeDB's rigorous type system. The type of all expressions is statically inferred by EdgeDB.
EdgeQL takes advantage of the graph-relational nature of EdgeDB schemas. Instead of tables and foreign keys, EdgeDB lets you think in objects, properties, and links. Deep queries that traverse links can be represented cleanly, no JOINs required.
EdgeQL prioritizes syntax over keywords; It uses { curly braces }
to define scopes/structures and the assignment operator :=
to set values. The result is a query language that looks more like code and less like word soup.
⋯
All queries below assume the following schema.
abstract type Person {
required name: str {
constraint exclusive;
};
}
type Villain extending Person {
nemesis: Hero;
}
type Hero extending Person {
secret_identity: str;
number_of_movies: int64;
multi link villains := .<nemesis[is Villain];
}
type Movie {
required title: str;
multi characters: Person;
}
It takes almost no time at all to learn the basics of querying in EdgeQL. It combines the intuitiveness of an ORM with the power of raw SQL.
select Hero {
id,
name,
secret_identity
};
[ { "id": "d3b353c6...", "name": "Peter Parker", "secret_identity": "Spider-Man" }, { "id": "af512f80-9d33-11eb-9a94-eb1b8a4d31ed", "name": "Barry Allen", "secret_identity": "The Flash" } ]
EdgeQL makes inserts, updates, upserts, deletes a breeze. Plus, its composable syntax makes nested mutations and upserts a joy to write.
insert Hero {
name := "Sam Wilson",
secret_identity := "The Falcon"
}
{"id": "5f22912a..."}
EdgeQL is no toy language; it supports polymorphic queries, a full slate of built-in convenience functions, JSON casting, and more.
select Hero {
id,
name,
movies := (
select Movie {
id, title
} filter Hero in .characters
)
}
SQL's lack of query composability is one of its biggest drawbacks. EdgeQL was designed with nestable subqueries in mind from the beginning. [ { "id": "90a2457e...", "name": "Tony Stark", "movies": [ { "id": "98ac6cf2...", "title": "The Avengers" } ] }, ... ]