Skip to content

Krishna-Sivakumar/vecclock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VecClock: A Vector Timestamp extension for SQLite

This extension adds vector timestamps to SQLite. Parallel timestamps are considered equal.

To use this, first compile it with make and then load it.

.load ./vecclock.so

To use this with a table, add a text column with the vecclock collate option.

CREATE TABLE log (
    id TEXT PRIMARY KEY,
    logtext TEXT NOT NULL,
    timestamp COLLATE vecclock NOT NULL
);
INSERT INTO log VALUES(1, 'log at init', vec_encode('[2, 0, 0]'));
INSERT INTO log VALUES(2, 'log at init', vec_encode('[0, 0, 3]'));

Querying with timestamps is as easy as:

SELECT logtext FROM log WHERE timestamp > vec_encode(1, 0, 0);
SELECT logtext FROM log WHERE timestamp >= vec_encode('[0, 0, 2]');

Functions available:

  1. vec_decode(): decodes a vector timestamp from blob to JSON.
select vec_decode(timestamp) from log;
  1. vec_encode(...): encodes a list of non-negative integers and returns a BLOB vector timestamp.
update log set timestamp = vec_encode(0, 0, 0) where id = 1;
  1. vec_encode_json(...): encodes a json array of non-negative integers and returns a BLOB vector timestamp.
update log set timestamp = vec_encode_json('[0, 0, 0]') where id = 1;

vec_decode() and vec_encode_json() are convenience functions for interoping with application code.

Notes

This project uses clangd as an LSP. Install it here.

Use bear to generate compile_commands.json in case it is missing, via bear -- make.

About

A vector timestamp extension for SQLite.

Topics

Resources

License

Stars

Watchers

Forks