Skip to content

Raw tables: Mention Swift support #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion usage/use-case-examples/raw-tables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Join our [Discord community](https://discord.gg/powersync) to share your experience and get help.
</Warning>

By default, PowerSync uses a [JSON-based view system](/architecture/client-architecture#schema) where data is stored schemalessly in JSON format and then presented through SQLite views based on the client-side schema. Raw tables allow you to define native SQLite tables in the client-side schema, bypassing this.

Check warning on line 16 in usage/use-case-examples/raw-tables.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

usage/use-case-examples/raw-tables.mdx#L16

Did you really mean 'schemalessly'?

This eliminates overhead associated with extracting values from the JSON data and provides access to advanced SQLite features like foreign key constraints and custom indexes.

Expand All @@ -24,6 +24,7 @@
- __JavaScript__ (Node: `0.8.0`, React-Native: `1.23.0`, Web: `1.24.0`)
- __Dart__: Version 1.15.0 of `package:powersync`.
- __Kotlin__: Version 1.3.0
- __Swift__: Version 1.3.0

Also note that raw tables are only supported by the new [Rust-based sync client](https://releases.powersync.com/announcements/improved-sync-performance-in-our-client-sdks), which is currently opt-in.
</Note>
Expand Down Expand Up @@ -74,10 +75,10 @@
#### Syncing into raw tables

To sync into the raw `todo_lists` table instead of `ps_data__`, PowerSync needs the SQL statements extracting
columns from the untyped JSON protocol used during syncing.

Check warning on line 78 in usage/use-case-examples/raw-tables.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

usage/use-case-examples/raw-tables.mdx#L78

Did you really mean 'untyped'?
This involves specifying two SQL statements:

1. A `put` SQL statement for upserts, responsible for creating a `todo_list` row or updating it based on its `id` and data columns.

Check warning on line 81 in usage/use-case-examples/raw-tables.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

usage/use-case-examples/raw-tables.mdx#L81

Did you really mean 'upserts'?
2. A `delete` SQL statement responsible for deletions.

The PowerSync client as part of our SDKs will automatically run these statements in response to sync lines being sent from the PowerSync Service.
Expand Down Expand Up @@ -175,11 +176,29 @@
</Tab>

<Tab title="Swift">
Unfortunately, raw tables are not available in the Swift SDK yet.
To define a raw table, include it in the list of tables passed to the `Schema`:

```Swift
let lists = RawTable(
name: "todo_lists",
put: PendingStatement(
sql: "INSERT OR REPLACE INTO todo_lists (id, created_by, title, content) VALUES (?, ?, ?, ?)",
parameters: [.id, .column("created_by"), .column("title"), .column("content")]
),
delete: PendingStatement(
sql: "DELETE FROM todo_lists WHERE id = ?",
parameters: [.id],
),
)

let schema = Schema(lists)
```
</Tab>

<Tab title=".NET">
Unfortunately, raw tables are not available in the .NET SDK yet.

------
</Tab>

</Tabs>
Expand Down Expand Up @@ -266,7 +285,7 @@
This does not apply if you've been using the raw table from the beginning (and never called `connect()` without them) - you only
need this for raw tables you already had locally.

Another workaround is to clear PowerSync data when changing raw tables and opt for a full resync.

Check warning on line 288 in usage/use-case-examples/raw-tables.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

usage/use-case-examples/raw-tables.mdx#L288

Did you really mean 'resync'?

### Migrating to raw tables

Expand Down