Light
Dark
System
1.0latest

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.

Installation

To get started, install the edgedb module from NPM.

Copy
$ 
npm install edgedb      # npm users
Copy
$ 
yarn add edgedb         # yarn users

There are two components of this library:

  • Use the driver establishes a connection to your database and executes queries.

  • Use the query builder to write queries in a code-first, typesafe way (if you wish)

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.

Copy
const edgedb = require("edgedb");

const client = edgedb.createClient();
const query = `select "Hello world!";`;

async function run(){
  const result = await client.query(query)
  console.log(result); // "Hello world!"
}

run();

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

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.

Copy
import e from "./dbschema/edgeql-js"; // auto-generated code

const query = e.select(e.Movie, (movie)=>({
  id: true,
  title: true,
  actors: { name: true },
  filter: e.op(movie.title, '=', 'Dune')
}));

const result = await query.run(client);
// { id: string; title: string; actors: {name: string}[] }[]

console.log(result.actors[0].name);
// => 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.

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.

Light
Dark
System