ElectricSQL is a local-first SQL system. It provides active-active cloud sync for embedded SQLite databases and a reactive programming model to bind components to live database queries.
The ElectricSQL Typescript Client is the main ElectricSQL client library for developing node, web and JavaScript-based mobile applications. It's designed to work with any SQLite driver or bindings, with convienience functions to integrate with the most popular ones, including the primary drivers for Expo, React Native, SQL.js and Node.js.
Instantiate and use your SQLite driver as normal and call electrify when opening a new database connection. For example using react-native-sqlite-storage:
import { electrify } from'electric-sql/react-native'// Import your SQLite driverimportSQLitefrom'react-native-sqlite-storage'SQLite.enablePromise(true)
// Import your app config and migrationsimport config from'.electric/@config'// Open an SQLite database connectionconst original = awaitSQLite.openDatabase('example.db')
// ⚡ Electrify itconst db = electrify(original, config)
// Use as normal, e.g.:
db.transaction((tx) => tx.executeSql('SELECT 1'))
Using in the web browser
Electric uses SQL.js in the browser with absurd-sql for persistence. This runs in a web worker (which we also use to keep background replication off the main thread). As a result, the electrified db client provides an asynchronous version of a subset of the SQL.js driver interface.
First create a worker.js file that imports and starts an ElectricWorker process:
import { initElectricSqlJs } from'electric-sql/browser'// Import your app config and migrationsimport config from'.electric/@config'// Start the background workerconst url = newURL('./worker.js', import.meta.url)
const worker = newWorker(url, { type: 'module' })
// Electrify the SQL.js / absurd-sql machineryconstSQL = awaitinitElectricSqlJs(worker, {
locateFile: (file) =>`/${file}`,
})
// Open a named database connectionconst db = awaitSQL.openDatabase('example.db', config)
This gives you persistent, local-first SQL with active-active replication
in your web browser 🤯. Use the db client as normal, with the proviso that
the methods are now async (they return promises rather than direct values).
Once electrified, you can bind live database queries to your reactive components, so they automatically update when data changes or comes in over the replication stream. For example:
We have an open community Discord. If you’re interested in the project, please come and say hello and let us know if you have any questions or need any help or support getting things running.
ElectricSQL TypeScript client for developing local-first SQL apps. Supports JavaScript based mobile, web and edge applications.
The npm package electric-sql receives a total of 156 weekly downloads. As such, electric-sql popularity was classified as not popular.
We found that electric-sql demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 3 open source maintainers collaborating on the project.
Package last updated on 21 Mar 2023
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.