sequel-xtdb 0.3.0 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -12
- data/lib/sequel/adapters/shared/xtdb.rb +59 -38
- data/lib/sequel/adapters/xtdb.rb +0 -6
- data/lib/sequel/xtdb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0f7d61f6d6a7c9ccb319122b964eb284815e959dfc2fa2b529f00195e2b8c91
|
4
|
+
data.tar.gz: 142f6c92856959dff66759cabef3c5cfbbe480eafda22d50ccc62d1e7178ebdb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0089ee3ce060d52540bac403359f66e334630787f1314a238482a28a8c2c49dd9415655d49c3d653cb8acefd052640d2c337f62b41e30f89ca3edd822625ca36'
|
7
|
+
data.tar.gz: 0f9a8848f64aba9c29424c073add18d6e64f78430add511866ce02b428254b741926ab89787473acfe8c72b9137ae6f61b0a8b1e2640b1fd8c346003faf4b8ba
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# sequel-xtdb
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/sequel-xtdb.svg?icon=si%3Arubygems)](https://badge.fury.io/rb/sequel-xtdb)
|
4
|
+
|
5
|
+
Adapter to connect to [XTDB](https://docs.xtdb.com/) v2 using [Sequel](https://sequel.jeremyevans.net/).
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -34,22 +36,20 @@ irb(main)> DB["select * from products"].all
|
|
34
36
|
|
35
37
|
### time-travel
|
36
38
|
|
37
|
-
_these examples use the [activesupport time helpers](https://api.rubyonrails.org/classes/ActiveSupport/Duration.html)_
|
38
|
-
|
39
39
|
```ruby
|
40
|
+
def shift_days(n, from: Time.now)= from + (60 * 60 * 24 * n)
|
40
41
|
DB = Sequel.connect("xtdb://localhost:5432/xtdb")
|
41
42
|
|
42
43
|
# get a dataset (ie query)
|
43
44
|
users = DB[:users]
|
44
|
-
|
45
|
-
ds1, ds2 = users.as_of(valid: past), users.as_of(valid: future)
|
45
|
+
ds1, ds2 = users.as_of(valid: shift_days(-2)), users.as_of(valid: shift_days(2))
|
46
46
|
|
47
47
|
# expect empty
|
48
48
|
ds1.all
|
49
49
|
ds1.insert(_id: 1, name: "James")
|
50
50
|
|
51
51
|
# expect a user
|
52
|
-
ds1.as_of(valid:
|
52
|
+
ds1.as_of(valid: shift_days(-1)).all
|
53
53
|
|
54
54
|
# add to future
|
55
55
|
ds2.insert(_id: 2, name: "Jeremy")
|
@@ -57,21 +57,24 @@ ds2.insert(_id: 2, name: "Jeremy")
|
|
57
57
|
# expect only James
|
58
58
|
users.all
|
59
59
|
# expect both James and Jeremy
|
60
|
-
ds2.as_of(valid:
|
60
|
+
ds2.as_of(valid: shift_days(3)).all
|
61
61
|
```
|
62
62
|
|
63
|
-
|
64
63
|
## Status
|
65
64
|
|
66
|
-
Very early days :)
|
67
|
-
Currently it's essentially the postgres-adapter with support for a xtdb-scheme url.
|
65
|
+
Very early days :)
|
68
66
|
|
69
67
|
|
70
68
|
## Development
|
71
69
|
|
72
70
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
|
73
71
|
|
74
|
-
You can also run `bin/console [xtdb-url]` for an interactive prompt that will allow you to experiment. The script will pick up on env-var `XTDB_URL`, though the argument takes precedence.
|
72
|
+
You can also run `bin/console [xtdb-url]` for an interactive prompt that will allow you to experiment. The script will pick up on env-var `XTDB_URL`, though the argument takes precedence. The console-script sets up (query-)logging.
|
73
|
+
|
74
|
+
Speaking of logging: best to start the XTDB docker container with debug-logging:
|
75
|
+
```
|
76
|
+
docker run -it --pull=always -e XTDB_LOGGING_LEVEL=debug -v $PWD/tmp/db:/var/lib/xtdb -p 6543:3000 -p 5432:5432 ghcr.io/xtdb/xtdb:nightly
|
77
|
+
```
|
75
78
|
|
76
79
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
77
80
|
|
@@ -1,6 +1,25 @@
|
|
1
|
+
require "sequel/adapters/utils/unmodified_identifiers"
|
2
|
+
|
1
3
|
module Sequel
|
2
4
|
module XTDB
|
5
|
+
Sequel::Database.set_shared_adapter_scheme :xtdb, self
|
6
|
+
|
7
|
+
def self.mock_adapter_setup(db)
|
8
|
+
db.instance_exec do
|
9
|
+
@server_version = 0
|
10
|
+
|
11
|
+
# def schema_parse_table(*)
|
12
|
+
# []
|
13
|
+
# end
|
14
|
+
# singleton_class.send(:private, :schema_parse_table)
|
15
|
+
# adapter_initialize
|
16
|
+
# extend(MockAdapterDatabaseMethods)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
3
20
|
module DatabaseMethods
|
21
|
+
include UnmodifiedIdentifiers::DatabaseMethods # ensure lowercase identifiers
|
22
|
+
|
4
23
|
def database_type
|
5
24
|
:xtdb
|
6
25
|
end
|
@@ -11,41 +30,19 @@ module Sequel
|
|
11
30
|
end
|
12
31
|
|
13
32
|
# Get a dataset with `current`, `valid` and `system` set.
|
14
|
-
#
|
15
|
-
# For selects this creates the SETTING pre-amble, e.g. 'SETTING DEFAULT VALID_TIME ...':
|
16
|
-
# ```
|
17
|
-
# DB.as_of(current: 2.weeks.ago).select(Sequel.lit('current_timestamp')).single_value
|
18
|
-
# ```
|
19
|
-
#
|
20
|
-
# A block can be provided as a convenience to stay in SQL-land (selects only):
|
21
|
-
# ```
|
22
|
-
# DB.as_of(current: 2.hours.ago) do
|
23
|
-
# DB["select current_timestamp"]
|
24
|
-
# end.sql
|
25
|
-
# =>
|
26
|
-
# SETTING
|
27
|
-
# CURRENT_TIME TO TIMESTAMP '2024-12-17T12:59:48+01:00'
|
28
|
-
# select current_timestamp
|
29
|
-
# ```
|
30
|
-
#
|
31
|
-
# When doing inserts, the `_valid_from` will be added (if not provided):
|
32
|
-
# ```
|
33
|
-
# DB[:products].as_of(valid: 2.weeks.ago).insert(_id: 1, name: 'Spam')
|
34
|
-
# ```
|
35
33
|
def as_of(...)
|
36
|
-
|
37
|
-
return ds unless block_given?
|
38
|
-
|
39
|
-
yield.clone(append_sql: ds.select_setting_sql(""))
|
34
|
+
@default_dataset.as_of(...)
|
40
35
|
end
|
41
36
|
end
|
42
37
|
|
43
38
|
module DatasetMethods
|
39
|
+
include UnmodifiedIdentifiers::DatasetMethods # ensure lowercase identifiers
|
40
|
+
|
44
41
|
Dataset.def_sql_method(self, :select,
|
45
42
|
[["if opts[:values]",
|
46
43
|
%w[values compounds order limit]],
|
47
44
|
["else",
|
48
|
-
%w[
|
45
|
+
%w[select distinct columns from join where group having compounds order limit lock]]])
|
49
46
|
|
50
47
|
def as_of(valid: nil, system: nil, current: nil)
|
51
48
|
{valid: valid, system: system, current: current}.reject { |_k, v| v.nil? }.then do |opts|
|
@@ -54,6 +51,8 @@ module Sequel
|
|
54
51
|
end
|
55
52
|
|
56
53
|
def server_version
|
54
|
+
# TODO 2_000_000 from xt.version() output
|
55
|
+
# requires all def_sql_methods
|
57
56
|
0
|
58
57
|
end
|
59
58
|
|
@@ -77,27 +76,49 @@ module Sequel
|
|
77
76
|
super
|
78
77
|
end
|
79
78
|
|
80
|
-
def
|
79
|
+
def select_sql
|
80
|
+
sql = super
|
81
|
+
|
82
|
+
if (setting = select_setting_sql)
|
83
|
+
if sql.frozen?
|
84
|
+
setting += sql
|
85
|
+
setting.freeze
|
86
|
+
elsif @opts[:append_sql] || @opts[:placeholder_literalizer]
|
87
|
+
setting << sql
|
88
|
+
else
|
89
|
+
setting + sql
|
90
|
+
end
|
91
|
+
else
|
92
|
+
sql
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def select_setting_sql
|
81
97
|
setting = opts.slice(:current, :valid, :system)
|
82
|
-
return
|
98
|
+
return if setting.empty?
|
83
99
|
|
84
100
|
cast_value = ->(v) do
|
85
|
-
case v
|
86
|
-
when DateTime, Time
|
87
|
-
|
88
|
-
when Date
|
89
|
-
literal_append "DATE ", v.iso8601
|
101
|
+
type = case v
|
102
|
+
when DateTime, Time then "TIMESTAMP"
|
103
|
+
when Date then "DATE"
|
90
104
|
end
|
105
|
+
literal_append "#{type} ", v.iso8601
|
91
106
|
end
|
92
|
-
sql
|
93
|
-
sql
|
107
|
+
sql = "SETTING "
|
108
|
+
sql.concat(setting.map do |k, v|
|
94
109
|
if k == :current
|
95
|
-
|
110
|
+
"CURRENT_TIME TO #{cast_value[v.to_time]}"
|
96
111
|
else
|
97
112
|
"DEFAULT #{k.upcase}_TIME AS OF #{cast_value[v]}"
|
98
113
|
end
|
99
|
-
end.join(", ")
|
100
|
-
sql
|
114
|
+
end.join(", "))
|
115
|
+
sql.concat " "
|
116
|
+
end
|
117
|
+
|
118
|
+
private
|
119
|
+
|
120
|
+
def default_timestamp_format
|
121
|
+
"'%Y-%m-%d %H:%M:%S'"
|
101
122
|
end
|
102
123
|
end
|
103
124
|
end
|
data/lib/sequel/adapters/xtdb.rb
CHANGED
data/lib/sequel/xtdb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel-xtdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gert Goet
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|