Skip to content

Raw table improvements#324

Open
simolus3 wants to merge 2 commits intomainfrom
raw-table-updates
Open

Raw table improvements#324
simolus3 wants to merge 2 commits intomainfrom
raw-table-updates

Conversation

@simolus3
Copy link
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.

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.

1 participant

Comments