electric-sql

Guidance skill for building local-first applications with ElectricSQL, applicable to real-time syncing of PostgreSQL data to client devices. Covers scenarios such as syncing the database to clients, local/offline-first synchronization, shape-based sync, real-time subscriptions, offline support, and conflict resolution.

Last repository push
GitHub Stars
219
Forks
38
Issues / PRs
7

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "electric-sql" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-8d3533298db4a7830b11c3b14e673e4565536421b95962b47d0e1e4cd04ed96f. Verify the upstream source and version against https://github.com/TerminalSkills/skills before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

github.com

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Guidance skill for building local-first applications with ElectricSQL, applicable to real-time syncing of PostgreSQL data to client devices. Covers scenarios such as syncing the database to clients, local/offline-first synchronization, shape-based sync, real-time subscriptions, offline support, and conflict resolution.

0 Downloads

Introduction source: third_party · TerminalSkills · 1.0.0 Reference

SkillPi interpretation

Audience
Apps that must work offline (field service, mobile, travel) Real-time collaborative features (shared lists, dashboards) Low-latency reads — querying local data is instant Reducing API calls — data is already on the client Multi-device sync (phone, tablet, desktop see same data)
Software, accounts and paid services
```bash
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: electric-sql
description: >-
  Build local-first applications with ElectricSQL — sync Postgres data to client
  devices in real-time. Use when someone asks to "sync database to client",
  "local-first app", "ElectricSQL", "offline-first sync", "real-time Postgres
  sync", "sync Postgres to SQLite", or "build an app that works offline".
  Covers shape-based sync, real-time subscriptions, offline support, and
  conflict resolution.
license: Apache-2.0
compatibility: "PostgreSQL. Clients: React, React Native, Expo, any HTTP client."
metadata:
  author: terminal-skills
  version: "1.0.0"
  category: data-ai
  tags: ["sync", "local-first", "offline", "postgres", "real-time"]

ElectricSQL

Overview

ElectricSQL syncs Postgres data to client applications in real-time. Instead of fetching data from an API, the data lives locally on the device — queries are instant, the app works offline, and changes sync automatically when connectivity returns. Think "Postgres replication to the browser." Define shapes (subsets of your data) and Electric keeps them in sync.

When to Use

  • Apps that must work offline (field service, mobile, travel)
  • Real-time collaborative features (shared lists, dashboards)
  • Low-latency reads — querying local data is instant
  • Reducing API calls — data is already on the client
  • Multi-device sync (phone, tablet, desktop see same data)

Instructions

Setup

# Server: Electric sync service
docker run -e DATABASE_URL=postgresql://... -p 3000:3000 electricsql/electric

# Client
npm install @electric-sql/react

Define Shapes (What to Sync)

// shapes.ts — Define what data to sync to the client
/**
 * Shapes are "live queries" — subsets of your Postgres data
 * that stay in sync on the client. Only sync what the user needs.
 */
import { ShapeStream } from "@electric-sql/client";

// Sync all todos for a specific user
const stream = new ShapeStream({
  url: "http://localhost:3000/v1/shape",
  params: {
    table: "todos",
    where: `user_id = '${userId}'`,
  },
});

// Stream delivers initial data + real-time updates
stream.subscribe((messages) => {
  for (const msg of messages) {
    if (msg.headers.operation === "insert") {
      console.log("New todo:", msg.value);
    }
  }
});

React Integration

// components/TodoList.tsx — Real-time synced todo list
import { useShape } from "@electric-sql/react";

interface Todo {
  id: string;
  title: string;
  completed: boolean;
  created_at: string;
}

export function TodoList({ userId }: { userId: string }) {
  // Data syncs automatically — no loading states for reads
  const { data: todos, isLoading } = useShape<Todo>({
    url: "http://localhost:3000/v1/shape",
    params: {
      table: "todos",
      where: `user_id = '${userId}'`,
      columns: ["id", "title", "completed", "created_at"],
    },
  });

  if (isLoading) return <div>Loading initial sync...</div>;

  // Reads are instant — data is local
  const active = todos.filter((t) => !t.completed);
  const done = todos.filter((t) => t.completed);

  return (
    <div>
      <h2>Active ({active.length})</h2>
      {active.map((todo) => (
        <div key={todo.id}>
          <input
            type="checkbox"
            onChange={() => toggleTodo(todo.id)}
          />
          {todo.title}
        </div>
      ))}

      <h2>Completed ({done.length})</h2>
      {done.map((todo) => (
        <div key={todo.id} style={{ textDecoration: "line-through" }}>
          {todo.title}
        </div>
      ))}
    </div>
  );
}

// Writes go through your API (Electric syncs the result back)
async function toggleTodo(id: string) {
  await fetch(`/api/todos/${id}/toggle`, { method: "PATCH" });
  // No need to refetch — Electric syncs the update automatically
}

Offline Support

// offline.ts — Electric handles offline automatically
/**
 * When the device goes offline, reads still work (data is local).
 * When connectivity returns, Electric syncs missed changes.
 * 
 * For writes during offline, queue them and replay on reconnect:
 */
const writeQueue: Array<() => Promise<void>> = [];

async function createTodo(title: string) {
  const action = () => fetch("/api/todos", {
    method: "POST",
    body: JSON.stringify({ title }),
  });

  if (navigator.onLine) {
    await action();
  } else {
    writeQueue.push(action);  // Queue for later
  }
}

// Replay queued writes when back online
window.addEventListener("online", async () => {
  while (writeQueue.length > 0) {
    const action = writeQueue.shift()!;
    await action();
  }
});

Examples

Example 1: Build an offline-capable task manager

User prompt: "Build a task manager that works without internet and syncs when back online."

The agent will set up Electric with shapes for user tasks, local reads with React hooks, write queue for offline mutations, and automatic sync on reconnect.

Example 2: Real-time dashboard

User prompt: "Build a dashboard that shows live data from our Postgres database without polling."

The agent will configure Electric shapes for dashboard metrics, subscribe to real-time updates, and render charts that update instantly as the database changes.

Guidelines

  • Shapes define what syncs — sync subsets of data, not entire tables
  • Reads are instant — data is local, no network round-trip
  • Writes go through your API — Electric syncs the result back to all clients
  • where for filtering — only sync data the user should see
  • columns for projection — reduce sync payload to needed fields
  • Postgres is the source of truth — Electric reads the WAL (Write-Ahead Log)
  • No schema changes needed — works with your existing Postgres schema
  • Shape streams are resumable — reconnects sync from where they left off
  • For offline writes, queue locally — replay when connectivity returns
  • Use with any framework — React hook is convenient, but the core client works anywhere

Current listing version

1.0.0

Verify the source revision ↗

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value88/100

Highlights

  • 解决本地优先、离线同步、实时数据同步等高频开发需求
  • 适用于多种客户端框架,实用性强
Trigger Precision92/100

Highlights

  • 触发词覆盖全面,包含多种常见用户表达变体
  • 边界清晰,不易误触或漏触
Structure and Standards95/100

Highlights

  • 结构清晰,步骤完整,含端到端示例
  • frontmatter 完整,文档规范
Execution Reliability90/100

Highlights

  • 工具来源明确,参数正确
  • 覆盖离线写入等异常处理场景
Evidence Verifiability (mean of the first four)91/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

  • Install or fetch external dependencies

    Use official sources and pin versions. Check install scripts in an isolated environment. This document check does not cover code downloaded later.

    Mentioned in main document · lines 42
Domains or addresses referenced in the document

These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.

  • localhost

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

```bash

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.