Skip to content

Raw table improvements#324

Merged
simolus3 merged 3 commits intomainfrom
raw-table-updates
Mar 2, 2026
Merged

Raw table improvements#324
simolus3 merged 3 commits intomainfrom
raw-table-updates

Conversation

@simolus3
Copy link
Copy Markdown
Contributor

Starting with 0.4.11, the core extension can infer the put and delete statements for raw tables automatically if the name of the table in the local schema is given. Additionally, the extension registers an SQL function to create triggers recording writes on raw tables in ps_crud.

This PR exposes the new functionality:

  1. The RawTableSchema class wraps the local table name (and optionally, information about local-only columns and advanced options). There are two public constructors on RawTable:
    • The existing one taking a PendingStatement for put and delete operations.
    • A new one taking a RawTableSchema instead. Put and delete statements can still be overridden, but they would be inferred by default.
  2. The powersync_create_raw_table_crud_trigger SQL function creating triggers would have to be called by the user in migration. It takes a JSON-serialized description of the raw table though, so the Kotlin SDK adds the jsonDescription() method returning that as a string. We don't want to expose the serializer publicly since that would increase the size of the Swift helper framework, serializing to a string keeps the rest internal.
  3. For explicit put statements, the new Rest parameter source can be used to make the core extension create a JSON object of columns that would otherwise be missing from the table. Having this available can help with migrations.

When creating triggers, PowerSync supports additional options like insertOnly and trackPreviousValues. Because triggers can now be created for raw tables as well, the same options are available. So, this refactors those parameters into a new TableOptions class. Existing constructors on Table continue to work unchanged (by forwarding parameters).
A minor breaking change is that table.copy(insertOnly=true) would no longer be supported because the field has moved to a different class. I've documented that, but I think the breaking change is worth it as it makes internals cleaner and I doubt many users were calling copy() on tables.

@simolus3 simolus3 force-pushed the raw-table-updates branch from 9565dd8 to ad3fef8 Compare March 2, 2026 07:15
Copy link
Copy Markdown
Contributor

@stevensJourney stevensJourney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that table.copy() has a rather niche use case. Happy with the changes.

@simolus3 simolus3 merged commit 453609e into main Mar 2, 2026
15 checks passed
@simolus3 simolus3 deleted the raw-table-updates branch March 2, 2026 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants