Skip to content
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

Function to handle after_update metadata tracking #363

Merged
merged 15 commits into from
Sep 26, 2023
Merged

Conversation

tantaman
Copy link
Collaborator

Creating a lookaside table for primary keys ends up making triggers rather complex since they must either update or consult this lookaside in multiple places and we are not able to store variables in triggers.

In other words, we have a bunch of

INSERT OR IGNORE INTO lookaside (...);
SELECT (SELECT key FROM lookaside WHERE ...), ...

The update trigger also installs more than one trigger for update in order to handle primary key changes since changing a primary key is an update + delete.

Triggers do not run in a deterministic order in SQLite so each trigger would need to write the lookaside.

To try to simplify all this, I'm moving everything into a function so triggers will become:

CREATE TRIGER foo AFTER INSERT ON bar BEGIN
  SELECT crsql_after_update('table', new_primary_keys, old_primary_keys, new_columns, old_columns);
END;

and crsql_after_update will do all the correct thing.

@tantaman tantaman changed the base branch from export-cleanup to main September 20, 2023 18:06
@tantaman tantaman changed the base branch from main to fix-errmsg-set September 20, 2023 18:07
@tantaman tantaman force-pushed the fix-errmsg-set branch 2 times, most recently from 37504dd to 1e9d3ff Compare September 20, 2023 18:17
@tantaman tantaman changed the base branch from fix-errmsg-set to main September 20, 2023 20:21
@tantaman tantaman changed the base branch from main to rust-db-version-fn September 20, 2023 20:22
@tantaman tantaman force-pushed the trigger-fns branch 5 times, most recently from cf32162 to 58bce82 Compare September 26, 2023 15:01
@tantaman tantaman changed the base branch from rust-db-version-fn to main September 26, 2023 18:33
@tantaman tantaman marked this pull request as ready for review September 26, 2023 18:34
@tantaman tantaman merged commit 80e1371 into main Sep 26, 2023
9 checks passed
@tantaman tantaman mentioned this pull request Sep 27, 2023
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