electric README

The project's README from github.com/electric-sql/electric. As one markdown file: README.md.

ElectricSQL logo

License - Apache 2.0 Status - Beta Chat - Discord

Electric

Real-time sync for Postgres.

Table of Contents:

What is Electric?

Sync is the magic ingredient behind fast, modern software. From apps like Figma and Linear to AI agents running on live local data.

Electric is a Postgres sync engine. It solves the hard problems of sync for you, including partial replication, fan-out, and data delivery. So you can build awesome software, without rolling your own sync.

Specifically, Electric is a read-path sync engine for Postgres. It syncs data out of Postgres into ... anything you like. The core sync protocol is based on a low-level HTTP API. This integrates with CDNs for highly-scalable data delivery.

Partial replication is managed using Shapes. Sync can be consumed directly or via client libraries and framework integrations.

Getting Started

See the Quickstart guide to get up and running. In short, you need to:

  1. have a Postgres database with logical replication enabled; and then to
  2. run Electric in front of it, connected via DATABASE_URL

For example, using Docker Compose from the root of this repo:

docker compose -f .support/docker-compose.yml up

You can then use the HTTP API to sync data from your Postgres. For example, to start syncing the whole foo table:

curl -i 'http://localhost:3000/v1/shape?table=foo&offset=-1'

Or use one of the clients or integrations, such as the useShape React hook:

import { useShape } from '@electric-sql/react'

function Component() {
  const { data } = useShape({
    url: `http://localhost:3000/v1/shape`,
    params: {
      table: `foo`,
      where: `title LIKE 'foo%'`,
    },
  })

  return JSON.stringify(data)
}

Again, see the Quickstart and the Docs for more details.

HTTP API Docs

The HTTP API is defined in an OpenAPI spec in website/electric-api.yaml.

Phoenix LiveDashboard

Electric includes an optional Phoenix LiveDashboard for real-time monitoring of the running system (VM metrics, process info, ETS tables, etc.).

To enable it, set the ELECTRIC_LIVE_DASHBOARD_PORT environment variable:

ELECTRIC_LIVE_DASHBOARD_PORT=4000

The dashboard will be available at http://localhost:4000 (or whichever port you choose). When the variable is not set, the dashboard is not started.

WARNING: The LiveDashboard endpoint is completely unauthenticated. Anyone with network access to the port can view internal system state. In production, you must restrict access to this port using firewall rules, network policies, or similar controls. Do not expose it to the public internet.

Developing Electric

We use asdf to install Elixir, Erlang, and Node.js. Versions are defined in .tool-versions.

Mac setup

brew install asdf
asdf plugin add nodejs
asdf plugin add pnpm
asdf plugin add elixir
asdf plugin add erlang
asdf install

You'll probably need to fiddle with your bash/zsh/etc rc file to load the right tool into your environment.

Running Tests

Electric has comprehensive test suites for both Elixir and TypeScript components.

Prerequisites

Install dependencies (if not already done):

asdf install
pnpm install

Then start the test Postgres database:

cd packages/sync-service
mix start_dev

This starts a Docker Compose setup with Postgres configured for logical replication on port 54321.

To stop the database:

mix stop_dev

Elixir Tests

Sync Service:

cd packages/sync-service
mix test

For coverage reports:

mix coveralls.html

Elixir Client:

cd packages/elixir-client
mix test

TypeScript Tests

TypeScript tests require both the database and a running sync service.

In a separate terminal, start the sync service:

cd packages/sync-service
iex -S mix

Then run the tests:

Individual Package:

cd packages/typescript-client  # or any other TS package
pnpm test

All TypeScript Packages:

From the root directory:

pnpm -r test

For coverage:

pnpm coverage

Contributing

See the:

Support

We have an open community Discord. Come and say hello and let us know if you have any questions or need any help getting things running.

It's also super helpful if you leave the project a star here at the top of the page☝️

electric (electric-sql/electric)

Searching Database…

10.4K ·GitHub
这是什么?Electric 是一个面向 Postgres 的实时同步引擎:它把数据从你的数据库复制到任何地方——Web 应用、移动客户端、AI 智能体——并替你处理那些麻烦的部分,比如部分复制、扇出和数据分发。
这是我加到应用里的库,还是需要自己部署的东西?它是一个独立运行的服务,部署在你的 Postgres 前面,而不是代码依赖。Electric 负责读取链路的同步,你的应用只需消费从它流出来的数据。
我怎么把它跑起来?通过 DATABASE_URL 指向一个开启了逻辑复制的 Postgres 数据库,然后把 Electric 运行在它前面——仓库里自带 Docker Compose 配置。接着调用 HTTP API 开始同步,比如同步一整张表。
除了 Postgres 本身,我还需要什么?只需要一个开启逻辑复制的 Postgres;快速上手用 Docker Compose 就能把 Electric 跑起来。如果要开发 Electric 本身,则需要通过 asdf 安装 Elixir、Erlang 和 Node.js。
在生产环境使用前有什么坑要注意?可选的 Phoenix LiveDashboard 监控端点完全没有身份验证:任何能访问该端口的人都能看到系统内部状态。请用防火墙规则限制访问,绝不要把它暴露到公网。
那它是给应用前端用的,还是给 AI 智能体用的?两者都是——既适合像 Figma 或 Linear 那样打造快速现代应用的团队,也适合需要基于本地实时数据运行、而不是反复轮询数据库的 AI 智能体。
Shape 是什么?它是部分复制的单位:你让 Electric 同步 Postgres 中定义好的一块数据——比如一整张表——由它负责把这部分数据分发给客户端。
数据实际上是怎么到达我的应用的?通过一个底层的基于 HTTP 的同步协议,它专为与 CDN 集成、实现高可扩展的分发而设计;也可以通过客户端库和框架集成来使用,比如 useShape 这个 React hook。
同步 API 的文档在哪里?在仓库里的一份 OpenAPI 规范中,路径是 website/electric-api.yaml。
Size
261.5 MB
Stars
10.4K
Age
4y
Commits · 90 Days