First, install EdgeDB if you haven’t already.
Use
bun init
to create a fresh project.
terminal
We’ll use the EdgeDB CLI to initialize an EdgeDB instance for our project. This creates an
edgedb.toml
file in our project root.
terminal
To see if the database is running, let’s open a REPL and run a simple query.
terminal
\quit
to exit the REPL.
terminal
With the project initialized, we can define a schema. The
edgedb project init
command already created a dbschema/default.esdl
file to contain our schema.
File Tree
Open that file and paste the following contents.
default.esdl
Then generate and apply an initial migration.
terminal
terminal
With our schema applied, let’s execute some queries using EdgeDB’s JavaScript client library. We’ll install the client library and EdgeDB’s codegen CLI, and create a
seed.ts
.file.
terminal
Paste the following code into
seed.ts
.
The client auto-connects to the database. We insert a couple movies using the .execute()
method. We will use EdgeQL’s for
expression to turn this bulk insert into a single optimized query.
Then run this file with Bun.
terminal
EdgeDB implements a number of code generation tools for TypeScript. To query our newly seeded database in a typesafe way, we’ll use
@edgedb/generate
to code-generate the EdgeQL query builder.
terminal
In
index.ts
, we can import the generated query builder from ./dbschema/edgeql-js
and write a simple select query.
Running the file with Bun, we can see the list of movies we inserted.
terminal
For complete documentation, refer to the EdgeDB docs.