EdgeQL

EdgeQL is a next-generation query language designed to match SQL in power and surpass it in terms of clarity, brevity, and intuitiveness.

All queries on this page assume the following schema. If you aren't familiar with how to model schemas in EdgeDB, check out the Data Modeling showcase.

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;
}
ConciseReadable

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"
  }
]
CompactComposable

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..."}
PowerfulFull-featured

Advanced features

EdgeQL is no toy query language. It supports complex query nesting, 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
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"
      }
    ]
  },
  ...
]