Expo
ElectricSQL supports Expo via expo-sqlite.
Dependencies
Add expo-sqlite
as a dependency to your app, e.g.:
npx expo install expo-sqlite
See the expo-sql docs for more information.
Usage
import * as SQLite from 'expo-sqlite'
import { electrify } from 'electric-sql/expo'
// Import your generated database schema.
import { schema } from './generated/client'
// Define your config with an least an auth token.
// See Usage -> Authentication for more details.
const config = {
auth: {
token: '...'
}
}
// Create the expo-sqlite database connection. The first argument
// is your database name. Changing this will create/use a new
// local database file.
const conn = SQLite.openDatabase('electric.db')
// Instantiate your electric client.
const electric = await electrify(conn, schema, config)
You can now use the client to read, write and sync data, e.g.:
const { db } = electric
const results = db.projects.findMany()
console.log(results)
See Usage -> Data access and Integrations -> Frontend for more information.