3 ms·
> select crsql_as_crr('foo'); This would be better served as an INSERT, since it's a modifying operation. I suggest INSERT INTO crsql VALUES ('as_crr', 'foo');
by CGamesPlay 4y ago
> select crsql_as_crr('foo');
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 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:
CREATE VIRTUAL TABLE foo USING crdt(col LWW);
INSERT INTO foo VALUES (1);
UPDATE foo SET col = crdt_set(2);
SELECT col, crdt_lww_timestamp(col_meta) FROM foo;
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')).
- Rygian 4y agoIn 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)?
- CGamesPlay 4y agoTechnically 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.
- tantaman 4y agoProject 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 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.
- cryptonector 4y agoYou can use views with INSTEAD OF triggers to handle INSERTs.
- faizshah 4y agoOP here, sorry if you didn’t want this posted yet. I had never seen such a simple way to implement realtime collaboration so I thought I would share it.
- tantaman 4y agonp. Gives me a good reason to finish up those usage docs and example apps :)