Skip to main content

Typescript client

Install the electric-sql library and npx electric-sql generate your database Client.



Install the published package:

yarn add electric-sql


The source code is in the clients/typescript subfolder of the electric-sql/electric repo.


Use the Generator script to generate a type-safe database client. First, make sure your sync service is running.

Then run:

npx electric-sql generate

By default this will connect to the sync service on http://localhost:5133 and output generated files to a ./src/generated/client folder.

See API -> Generator script for the command-line options.


The generator script outputs a database schema, type-safe database client and bundled SQL migrations. See Usage -> Data access -> Client for details on how to import and use these when instantiating a database client.

Pre-build script

You can wire up the generator to run every time you build your app by adding a prebuild script to your package.json:

"scripts": {
"prebuild": "npx electric-sql generate"
// ...

Watch mode

Or you can run the generator in --watch mode:

npx electric-sql generate --watch

This monitors the sync service to pick up on database schema changes and automatically re-generate the client whenever the DDL schema or DDLX rules change.