Skip to main content
Write data using SQL INSERT, UPDATE, or DELETE statements. PowerSync automatically queues these writes and uploads them to your backend via the uploadData() function in your backend connector.

Basic Write Operations

// Insert a new todo
await db.execute(
  'INSERT INTO todos (id, created_at, list_id, description) VALUES (uuid(), date(), ?, ?)',
  [listId, 'Buy groceries']
);

// Update a todo
await db.execute(
  'UPDATE todos SET completed = 1, completed_at = date() WHERE id = ?',
  [todoId]
);

// Delete a todo
await db.execute('DELETE FROM todos WHERE id = ?', [todoId]);
Best practice: Use UUIDs when inserting new rows on the client side. UUIDs can be generated offline/locally, allowing for unique identification of records created in the client database before they are synced to the server. See Client ID for more details.

ORM Support

PowerSync integrates with popular ORM libraries, which provide type safety and additional tooling. Using an ORM is often preferable to writing raw SQL queries, especially for common operations. See ORM Support to learn which ORMs PowerSync supports and how to get started.

Write Operations and Upload Queue

PowerSync automatically queues writes and uploads them to your backend. The upload queue stores three types of operations:
OperationPurposeContentsSQLite Statement
PUTCreate new rowContains the value for each non-null columnGenerated by INSERT statements.
PATCHUpdate existing rowContains the row id, and value of each changed column.Generated by UPDATE statements.
DELETEDelete existing rowContains the row idGenerated by DELETE statements.
For details on how writes are uploaded to your backend, see Writing Client Changes.

Advanced Topics