Re:Crsql – Multi-writer and CRDT support for SQLite
by Rygian on Tuesday November 15, 2022 @08:18AM
(#33608767)
In your example, why does the INSERT in second row use the unqualified value (1), but the UPDATE in third row uses a wrapped value as crdt_set(2)?
Re:Crsql – Multi-writer and CRDT support for SQLite
by CGamesPlay on Tuesday November 15, 2022 @08:49AM
(#33609099)
Technically it isn't necessary to use the wrapped value when the wrapper function only takes a single parameter (because the virtual table could easily do the wrapping in this case). In the case of an insert, all wrappers only ever take a single parameter so it can be elided, but for updates some wrappers may require multiple parameters, so I opted for consistency and force all updates to use the wrapper methods, even when it only takes a single parameters.
Re:Crsql – Multi-writer and CRDT support for SQLite
by tantaman on Tuesday November 15, 2022 @11:50AM
(#33611620)
Project author here (although not OP)
I like the idea of moving the syntax to inserts and had not seen https://www.sqlite.org/fts5.html#special_insert_commands
Will give it a shot & thanks for the resources.
> I personally am working on this problem, but I am approaching it from ephemeral tables.
Would love to trade ideas if you're open to it. @tantaman on twitter.
> Does this support CRDTs other than last-write-wins registers?
Not yet. I was thinking of collaborating with Seph to bring DiamondTypes in for sequence crdt support. If that is even possible -- just an idea at the moment.
Re:Crsql – Multi-writer and CRDT support for SQLite
by cryptonector on Tuesday November 15, 2022 @12:41PM
(#33612429)
You can use views with INSTEAD OF triggers to handle INSERTs.
This would be better served as an INSERT, since it's a modifying operation. I suggest INSERT INTO crsql VALUES ('as_crr', 'foo'); (this involves creating an ephemeral table called crsql). Similarly, instead of select crsql_finalize() you should use INSERT INTO crsql VALUES ('finalize'). This is the preferred way of doing this kind of metadata operation in SQLite, see https://www.sqlite.org/fts5.html#special_insert_commands for some examples.
Does this support CRDTs other than last-write-wins registers?
I personally am working on this problem, but I am approaching it from ephemeral tables. This allows lots more flexibility at the cost of more complex syntax. For a simple last-write-wins register, you might use something like:
This weird update syntax allows you to use non-standard operations, though, which then allows you to implement things like ordered sequences (text) in a conflict-free manner (e.g. SET col = crdt_text_insert(col, 5, ', world')).