crsql_tracked_peers is a table for tracking what updates have been received from peers or sent to peers.
This table is useful for authors of custom network / syncing layers. While
crsqlite will automatically insert & update rows for peers when applying changes via
INSERT INTO crsql_changes ..., users of
crsqlite may also insert or update rows of this table for their own purposes.
Coming soon: If you do not want
crsqliteto do any automatic tracking of peers, provide -1 to the hidden column
crsql_changeswhen performing an insert. You may also set
tagto any other nonzero custom value
CREATE TABLE crsql_tracked_peers( [site_id] BLOB NOT NULL, [version] INTEGER NOT NULL, [tag] INTEGER, [event] INTEGER, PRIMARY KEY ([site_id], [tag], [event]) ) STRICT;
- site_id - the unique id of the peer
- version - falls into two categories:
- For receive events: The clock value we last received from that peer
- For send events: The clock value we last sent that peer. I.e., For sends, this is our db's clock not the peer's.
- tag - used to differentiate sync sets. Tag is set to
0for whole database syncs. Inserts into
crsql_changeswhere tag is set to
-1will not create tracking events. If you're only syncing subsets of the databse then this tag represents the subset you're syncing, such as an id of a "root node" of some sub-graph. Coming soon -- see docs/replicated-subgraphs
- event - 0 for receive events, 1 for send events. Values below 1000 are reserved for
crsqlite automatically inserts & updates this table when processing inserts into
crsql_changes. On transaction commit,
- Inserts rows for
eventtuples that have not been seen before the current transaction, setting their
clockto the maximum value seen by
crsql_changesin the current transaction.
- Updates rows for
eventtuples that were seen in prior transactions, setting their
clockto the max of the existing value and the max seen in the current transaction.
If the user does not provide a
tag value during insert to
crsql_changes it is set to
crsqlite only updates
tracked_peers on receive events and thus always sets event to
0. Custom sync providers can use this table to track send events by setting the event to
1 on insert.
See the sync guide to understand how to leverage this table when creating a custom sync provider.
- All other values are open for use by clients.
- [2-1000] - reserved
- All other values are open for use by clients. Prefer
eventif you need to track many version for a given peer.