Registry / database / svelte-electricsql

svelte-electricsql

JSON →
library0.1.4jsnpmunverified

Svelte integration for ElectricSQL, a Postgres sync engine that provides an HTTP interface to Postgres, enabling massive numbers of clients to query and receive real-time updates to data in 'shapes' (subsets of the database). Current stable version is 0.1.4. This package provides a `useShape` hook that pulls shape data into Svelte components. It caches Shape and ShapeStream instances globally, making reuse across components efficient. Requires Svelte 5 and TypeScript types are included. Released in 2025 with no regular release cadence yet.

npm install svelte-electricsql
INSTALL
IMPORT
SIG · SVELTE-ELECTRICSQL
S
svelte-electricsql
databasejavascriptv0.1.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

useShape
import { useShape } from 'svelte-electricsql'
import useShape from 'svelte-electricsql'
useShape is a named export, not default. ESM only.
Shape
import { Shape } from 'svelte-electricsql'
const Shape = require('svelte-electricsql').Shape
Shape is exported as a class. ESM only as of v0.1.4; no CJS support.
ShapeStream
import { ShapeStream } from 'svelte-electricsql'
ShapeStream is exported for advanced usage. TypeScript types available.

Shows use of useShape hook to fetch and display reactive data from an ElectricSQL shape.

<script> import { useShape } from 'svelte-electricsql'; const shape = useShape({ url: process.env.ELECTRIC_URL ?? 'http://localhost:3000/v1/shape', params: { table: 'items' } }); </script> <h1>Items</h1> {#if shape.loading} <p>Loading...</p> {:else} <ul> {#each shape.data as item, i} <li>{i + 1}: {item.name}</li> {/each} </ul> {/if}
Debug
Known issues
gotchaDo not destructure the shape object returned by useShape. The shape object is reactive and will not update if destructured.
fix
Access properties directly on the shape object (e.g., shape.data, shape.loading).
affects: >=0.1.0
breakingSvelte 5 is required as peer dependency. Older Svelte versions are not supported.
fix
Upgrade to Svelte 5.
affects: >=0.1.0
deprecatedCJS support is discontinued; only ESM is provided.
fix
Use ESM imports; do not use require().
affects: >=0.1.0
Errors
Common errors & fixes
Cannot destructure property 'data' of 'shape' as it is undefined.
Destructuring the reactive shape object breaks reactivity.
fix
Do not destructure; use shape.data directly in the template.
ERR_REQUIRE_ESM: require() of ES Module not supported.
Package is ESM-only; using require() fails.
fix
Use import statements instead of require().
Upgrade
Version history
0.1.4latest on npm
Audit
Dependencies
svelterequiredpeer dependency required for Svelte integration
Agent activity
14 hits · last 30 days
node
12
Meta
1
OpenAI (training)
1
Resources
svelte-electricsql — npm install svelte-electricsql · libregistry