Happy to announce the (early) release of sequel-xtdb (repo), a Ruby driver for XTDB v2 built on Sequel.
This adapter (currently) leans heavily on the postgres-adapter, with the following additions:
- XTDB-url support.
- bi-temporal inserting.
# will add attribute _valid_from ds.as_of(valid: ...).insert(_id: 1, name: "Gert")
- bi-temporal querying.
# prefixes query with `SETTING DEFAULT VALID_TIME ...` DB[:users].as_of(valid: ..., system: ..., current: ...).all
goals
- step away from postgres-adapter
- have an example Rails-project
- support all DML/query syntax
- support more types
sample code
def shift_days(n, from: Time.now)= from + (60 * 60 * 24 * n)
DB = Sequel.connect("xtdb://localhost:5432/xtdb")
# (mostly) regular SQL
DB << "insert into users(_id, name) values(1, 'Jeremy')"
DB["select * from users"].all
# with placeholders
DB << Sequel.lit(<<-SQL, shift_days(14))
insert into users(_id, name, _valid_from) values(2, 'James', timestamp ?)
SQL
# Sequel DSL using the adapter's `as_of`
DB.as_of(valid: shift_days(15)).with_sql("select * from users").all
yesterday = DB[:users].as_of(valid: shift_days(-1))
yesterday.insert(_id: 3, name: "Gert")
DB[:users].all