EdgeQL

EdgeQL is a spiritual successor to SQL designed with a few core principles in mind.

Compatible with modern languages. 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.

Strongly typed. EdgeQL is inextricably tied to EdgeDB's rigorous type system. The type of all expressions is statically inferred by EdgeDB.

Designed for programmers. 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.

Easy deep querying. 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.

Composable. Unlike SQL, EdgeQL's syntax is readily composable; queries can be cleanly nested to perform subqueries or nested mutations.

All queries below assume the following schema.

Copy
abstract type Person {
  required property name -> str {
    constraint exclusive;
  };
}

type Villain extending Person {
  link nemesis -> Hero;
}

type Hero extending Person {
  property secret_identity -> str;
  property number_of_movies -> int64;
  multi link villains := .<nemesis[is Villain];
}

type Movie {
  required property title -> str;
  multi link characters -> Person;
}

Basic querying

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.

Selection sets
Filtering
Filter by ID
Deep fetching
Computed properties
Backward links
Copy
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"
  }
]

Mutation

EdgeQL makes inserts, updates, upserts, deletes a breeze. Plus, its composable syntax makes nested mutations and upserts a joy to write.

Insert
Update
Delete
Nested inserts
Upsert
Copy
insert Hero {
  name := "Sam Wilson",
  secret_identity := "The Falcon"
}
{"id": "5f22912a..."}

Advanced features

EdgeQL is no toy language; it supports polymorphic queries, a full slate of built-in convenience functions, JSON casting, and more.

Subqueries
Unions
With clauses
JSON casting
Aggregation
Type intersections
Polymorphism
Introspection
Grouping
Copy
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"
      }
    ]
  },
  ...
]