This repo contains example applications illustrating how to use ElectricSQL with various drivers and frameworks.
See the sub folders for the actual applications:
- expo — example mobile app using Expo with the expo-sqlite driver
- react-native — example mobile app using React Native with the react-native-sqlite-storage driver
- web — example web application using ElectricSQL in the browser with SQL.js and absurd-sql
Each example has usage instructions in the README. It may also be helpful to read through the ElectricSQL usage documentation, including the sections on configuration, migrations and the relevant section of the drivers guide.
As a local-first system, ElectricSQL defaults to working without a backend. So you can run these applications without connecting to a replication service. However, to develop, test and run with replication working, you'll need to configure a backend to connect to.
The simplest way to configure a backend is to sign up to ElectricSQL and create an application. This will give you a globally unique app
slug and an environment name. Paste this into your application config, which in these examples is typically defined in an electric-config.js
file in the root of the example folder, e.g.:
const config = {
app: '<YOUR APP SLUG>',
env: '<YOUR ENV NAME>',
// ... other configuration options ...
};
Alternatively, you can clone the electric-sql/electric repo and run locally using Makefile, Docker and Elixir 1.14 compiled with Erlang 24.
See the electric repo README for instructions but in short:
git clone https://github.com/electric-sql/electric
cd electric
make start_dev_env
make deps compile
Make sure you've built your migrations in your application folder, then set the MIGRATIONS_DIR
environment variable to the path to the migrations folder:
export MIGRATIONS_DIR='../path/to/migrations'
Now run the electric service:
make shell
Apply the migrations locally:
make apply_migration name=$MIGRATION_NAME
Where MIGRATION_NAME
is the name of a migration folder created using electric migrations new
, for example:
make apply_migration name=1666288253_create_items
You can then configure your application to connect to the local backend using the replication
config options:
const config = {
replication: {
address: 'localhost',
port: 5133
},
// ... other configuration options ...
};
See the documentation and community guidelines. If you need help let us know on Discord.