EdgeDB TypeScript/JS Client

This is the official EdgeDB client library for JavaScript and TypeScript. It’s the easiest way to connect to your database and execute queries from a Node.js or Deno backend.

We recently released v0.21.0 of the edgedb module on NPM and deno.land/x, which supports the latest EdgeDB 2.0 features and protocol. It is also backwards-compatible with v1 instances as well, so we recommend all users upgrade. Read the release notes for details.

There are two components of this library:

  • Use the Driver API to establish a connection to your database and execute EdgeQL queries (written as strings).

  • Use the Query Builder API to write queries in a code-first, typesafe way. Recommended for TypeScript users.

Requirements

Node.js users

  • [Node only] Node.js 14+. Run node --version to see your current version

  • [Deno only] Deno v1.17+. Run deno --version to see your current version

  • [TypeScript only] Node.js type declarations: npm install @types/node

  • [TypeScript only] "strict": true in tsconfig.json compilerOptions

Installation

Node users: Install the edgedb module from NPM.

  1. $
  1. npm install edgedb # npm users
  1. $
  1. yarn add edgedb # yarn users

Deno users: Import from deno.land/x/edgedb:

  1. import * as edgedb from "https://deno.land/x/edgedb/mod.ts"

The driver

The driver implements the core functionality required to establish a connection to your database and execute queries. If you prefer writing queries as strings, the driver API is all you need.

  1. const edgedb = require("edgedb");
  2. const client = edgedb.createClient();
  3. const query = `select "Hello world!";`;
  4. async function run(){
  5. const result = await client.query(query)
  6. console.log(result); // "Hello world!"
  7. }
  8. run();

If you’re not using TypeScript, you can skip straight to the Driver docs.

The query builder

The EdgeDB query builder provides a code-first way to write fully-typed EdgeQL queries with TypeScript. We recommend it for TypeScript users and JavaScript users who prefer writing queries as code.

  1. import e from "./dbschema/edgeql-js"; // auto-generated code
  2. const query = e.select(e.Movie, (movie)=>({
  3. id: true,
  4. title: true,
  5. actors: { name: true },
  6. filter: e.op(movie.title, '=', 'Dune')
  7. }));
  8. const result = await query.run(client);
  9. // { id: string; title: string; actors: {name: string}[] }
  10. // property `title` is exclusive
  11. console.log(result.actors[0].name);
  12. // => Timothee Chalamet

Is it an ORM?

No—it’s better! Like any modern TypeScript ORM, the query builder gives you full typesafety and autocompletion, but without the power and performance tradeoffs. You have access to the full power of EdgeQL and can write EdgeQL queries of arbitrary complexity. And since EdgeDB compiles each EdgeQL query into a single, highly-optimized SQL query, your queries stay fast, even when they’re complex.

How do I get started?

We recommend reading the Driver docs first. If you are happy writing your EdgeQL as plain strings, then that’s all you need! If you’re a TypeScript user, or simply prefer writing queries in a code-first way, continue on to the Query builder docs.