- Home
- Skills
- Mobile Development
- Expo + Supabase Offline-First Sync
Expo + Supabase Offline-First Sync
Builds offline-first sync for Expo apps on Supabase: SQLite outbox, server_seq pull cursor, last-write-wins conflicts, soft deletes, and the locking that stops rows being silently skipped.
Free
Works with the AI Agents you already use
Expo + Supabase Offline-First Sync
Example session with this skill installed
I need to set up the SQLite outbox table and a write function that ensures the outbox is updated whenever I save a new 'task' to my local Expo database.
- Read your context and instructions
- Compiled the expo + supabase
I have defined the SQLite schema for your outbox and implemented the transactional write pattern. This ensures that every task saved locally is queued for sync without risking data inconsistency.
SQLite Outbox Implementation
-- Run this in your local SQLite migration
CREATE TABLE outbox (
id INTEGER PRIMARY KEY AUTOINCREMENT,
tableName TEXT NOT NULL,
rowId TEXT NOT NULL,
op TEXT NOT NULL,
payload TEXT NOT NULL,
createdAt INTEGER NOT NULL,
attempts INTEGER DEFAULT 0
);
CREATE TABLE sync_state (
tableName TEXT PRIMARY KEY,
lastSeq INTEGER DEFAULT 0
);
// Local write module for Expo/Drizzle
function upsertTask(db, taskValues) {
const updatedAt = new Date().toISOString();
const result = db.transaction((tx) => {
// 1. Update the local data table
tx.insert(tasks)
.values({ ...taskValues, updatedAt, deletedAt: null })
.onConflictDoUpdate({
target: tasks.id,
set: { ...taskValues, updatedAt, deletedAt: null }
}).run();
const saved = tx.select().from(tasks).where(eq(tasks.id, taskValues.id)).get();
// 2. Queue the change in the outbox
tx.insert(outbox).values({
tableName: 'tasks',
rowId: saved.id,
op: 'upsert',
payload: JSON.stringify(saved),
createdAt: Date.now(),
}).run();
return saved;
});
// 3. Trigger the sync engine
notifyChanged('tasks', 'outbox');
return result;
}
Next steps
- Add the
server.sqltriggers to your Supabase instance to track sequences. - Initialize the
sync_statetable with your current table names. - Call
syncNow()from youruseEffector network listener to push these changes.
Connects securely to your tools. The creator never sees your data.
About this skill
Teaches your coding agent to build a complete offline-first sync engine for an Expo (React Native + web) app on Supabase, with no extra sync service. The UI reads and writes only local SQLite, and a background engine moves changes to and from Postgres.
The pattern comes from the sync engine of a real offline-first expense app with shared wallets.
What's included
SKILL.md: the rules, client code patterns, sync triggers, sharing, web setup, known limits and a pre-ship test checklistreferences/server.sql: a ready-to-adapt Postgres setup with the sequence, trigger, RLS policy,push_changesandpull_changes
What it covers
- Local writes: a row upsert and an outbox insert in one SQLite transaction
- Push: batched, atomic, and safe if the user edits a row while a request is in flight
- Pull: by server-assigned
server_seq, so wrong device clocks don't break it - Conflicts: last-write-wins per row, with soft deletes that sync to other devices
- Shared data: why a pull cursor misses old rows that become newly visible, and how to fix it
- Web: SQLite-WASM with OPFS, the COOP/COEP headers, and offline loading
The bug most custom sync engines have
Sequence values are handed out before commit. One transaction can take seq 10 and commit after another commits seq 11. A pull that sees 11 moves past 10 and never sees that row, so data goes missing silently. The included SQL prevents this with an advisory lock.
Good fit
Personal or small-team apps with row-level conflicts and a few thousand rows per user.
Not a good fit
- Collaborative editing inside one field: use a CRDT instead
- Many users writing constantly to one database: the lock is global, so every pull briefly blocks writers. The skill explains this limit.
Testing
The server SQL passed 20 checks on a throwaway Postgres with a stubbed Supabase auth schema, covering conflicts, row-level security, rollback and the pull/write race. The client snippets are patterns to adapt, not a drop-in library.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Mobile Development.
Last-write-wins uses device clocks and works per row, so two devices editing different fields of a row still lose one edit
The sync lock is global, so every pull briefly blocks writers; not meant for many users writing constantly to one database
Client code is patterns to adapt, not a drop-in library, and the server SQL assumes Supabase
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Free to use
No account required to browse
Trust & safety
Security scan
Security scan passed 13 days ago
- Free with an Agensi account
- Accounts
- Supabase
- Software
- Expo
Docker (for local Supabase testing)
Node.js