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

improved syntax for CRR / CRDT creation #324

Merged
merged 12 commits into from
Aug 15, 2023
Merged

improved syntax for CRR / CRDT creation #324

merged 12 commits into from
Aug 15, 2023

Conversation

tantaman
Copy link
Collaborator

@tantaman tantaman commented Aug 14, 2023

Allows creation of crrs via virtual table declaration.

Instead of:

CREATE TABLE foo (
  id INT PRIMARY KEY,
  content TEXT,
  other_thing FLOAT
);
SELECT crsql_as_crr('foo');

Users can now:

CREATE VIRTUAL TABLE foo_schema USING CRDT_TYPE (
    id INT PRIMARY KEY,
    content TEXT,
    other_thing FLOAT
);

which will create a table foo as a CRR. foo_schema exists as.. an unfortunate requirement but it has some benefits.

Altering CRRs would now be:

INSERT INTO foo_schema ("ALTER TABLE foo ...");

rather than

SELECT crsql_begin_alter('foo');
ALTER TABLE foo ...
SELECT crsql_end_alter('foo');

Neither of these are ideal but the insertion against the schema table seems less error prone. It could also, maybe, allow more declarative schema management:

UPDATE foo_schema SET schema = "NEW_SCHEMA";

Where we use our auto_migrate plugin to apply the correct schema modifications to update foo to the newly supplied schema.


Future iterations will extend this syntax to allow specifying CRDT type on a per-column basis.

Fixes #181

@tantaman tantaman changed the title Vtab improved syntax for CRR / CRDT creation Aug 14, 2023
@tantaman
Copy link
Collaborator Author

tantaman commented Aug 14, 2023

Note that this does not replace the old APIs of

SELECT crsql_as_crr(...)
and begin/end_alter(...)

This is new syntax for people allergic to mutations done through SELECT and to support later features of column-specific CRDT types (e.g., a counter column or a fugue column).

@tantaman
Copy link
Collaborator Author

You can't alter the CRRs via the virtual tables yet (although the existing alter APIs still work). Will do that in a follow up PR.

@tantaman tantaman merged commit 705152e into main Aug 15, 2023
12 checks passed
@tantaman tantaman deleted the vtab branch August 22, 2023 00:31
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.

Use CREATE VIRTUAL TABLE rather than select crsql_as_crr
1 participant