extralite-bundle 2.5 → 2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +34 -13
- data/Gemfile +4 -0
- data/Gemfile-bundle +1 -1
- data/LICENSE +1 -1
- data/README.md +1059 -247
- data/Rakefile +18 -0
- data/TODO.md +0 -7
- data/examples/kv_store.rb +49 -0
- data/examples/multi_fiber.rb +16 -0
- data/examples/on_progress.rb +9 -0
- data/examples/pubsub_store_polyphony.rb +194 -0
- data/examples/pubsub_store_threads.rb +204 -0
- data/ext/extralite/changeset.c +463 -0
- data/ext/extralite/common.c +177 -91
- data/ext/extralite/database.c +745 -276
- data/ext/extralite/extconf-bundle.rb +10 -4
- data/ext/extralite/extconf.rb +34 -34
- data/ext/extralite/extralite.h +104 -47
- data/ext/extralite/extralite_ext.c +6 -0
- data/ext/extralite/iterator.c +14 -86
- data/ext/extralite/query.c +171 -264
- data/extralite-bundle.gemspec +1 -1
- data/extralite.gemspec +1 -1
- data/gemspec.rb +10 -11
- data/lib/extralite/version.rb +1 -1
- data/lib/extralite.rb +69 -10
- data/lib/sequel/adapters/extralite.rb +1 -1
- data/test/helper.rb +9 -1
- data/test/perf_argv_transform.rb +74 -0
- data/test/perf_ary.rb +14 -12
- data/test/perf_hash.rb +17 -15
- data/test/perf_hash_prepared.rb +58 -0
- data/test/perf_hash_transform.rb +66 -0
- data/test/perf_polyphony.rb +74 -0
- data/test/test_changeset.rb +161 -0
- data/test/test_database.rb +720 -104
- data/test/test_extralite.rb +2 -2
- data/test/test_iterator.rb +28 -13
- data/test/test_query.rb +352 -110
- data/test/test_sequel.rb +4 -4
- metadata +24 -16
- data/Gemfile.lock +0 -37
- data/test/perf_prepared.rb +0 -64
@@ -0,0 +1,161 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'helper'
|
4
|
+
|
5
|
+
require 'date'
|
6
|
+
require 'tempfile'
|
7
|
+
|
8
|
+
class ChangesetTest < Minitest::Test
|
9
|
+
def setup
|
10
|
+
@db = Extralite::Database.new(':memory:')
|
11
|
+
skip if !@db.respond_to?(:track_changes)
|
12
|
+
|
13
|
+
@db.execute('create table if not exists t (x integer primary key, y, z)')
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_each
|
17
|
+
changeset = Extralite::Changeset.new
|
18
|
+
|
19
|
+
changeset.track(@db, [nil]) do
|
20
|
+
@db.execute('insert into t values (1, 2, 3)')
|
21
|
+
end
|
22
|
+
changes = []
|
23
|
+
changeset.each { |*o| changes << o }
|
24
|
+
assert_equal [
|
25
|
+
[:insert, 't', nil, [1, 2, 3]]
|
26
|
+
], changes
|
27
|
+
|
28
|
+
|
29
|
+
changeset.track(@db, [nil]) do
|
30
|
+
@db.execute('update t set y = 22 where x = 1')
|
31
|
+
end
|
32
|
+
changes = []
|
33
|
+
changeset.each { |*o| changes << o }
|
34
|
+
assert_equal [
|
35
|
+
[:update, 't', [1, 2, nil], [nil, 22, nil]]
|
36
|
+
], changes
|
37
|
+
|
38
|
+
|
39
|
+
changeset.track(@db, [nil]) do
|
40
|
+
@db.execute('delete from t where x = 1')
|
41
|
+
end
|
42
|
+
changes = []
|
43
|
+
changeset.each { |*o| changes << o }
|
44
|
+
assert_equal [
|
45
|
+
[:delete, 't', [1, 22, 3], nil]
|
46
|
+
], changes
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_to_a
|
50
|
+
changeset = Extralite::Changeset.new
|
51
|
+
|
52
|
+
changeset.track(@db, [nil]) do
|
53
|
+
@db.execute('insert into t values (1, 2, 3)')
|
54
|
+
@db.execute('insert into t values (4, 5, 6)')
|
55
|
+
end
|
56
|
+
assert_equal [
|
57
|
+
[:insert, 't', nil, [1, 2, 3]],
|
58
|
+
[:insert, 't', nil, [4, 5, 6]]
|
59
|
+
], changeset.to_a
|
60
|
+
|
61
|
+
|
62
|
+
changeset.track(@db, [nil]) do
|
63
|
+
@db.execute('update t set y = 22.22 where z < 10')
|
64
|
+
end
|
65
|
+
assert_equal [
|
66
|
+
[:update, 't', [1, 2, nil], [nil, 22.22, nil]],
|
67
|
+
[:update, 't', [4, 5, nil], [nil, 22.22, nil]]
|
68
|
+
], changeset.to_a
|
69
|
+
|
70
|
+
|
71
|
+
changeset.track(@db, [nil]) do
|
72
|
+
@db.execute('delete from t where x = 1')
|
73
|
+
end
|
74
|
+
assert_equal [
|
75
|
+
[:delete, 't', [1, 22.22, 3], nil]
|
76
|
+
], changeset.to_a
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_apply
|
80
|
+
changeset = Extralite::Changeset.new
|
81
|
+
|
82
|
+
changeset.track(@db, [:t]) do
|
83
|
+
@db.execute('insert into t values (1, 2, 3)')
|
84
|
+
@db.execute('insert into t values (4, 5, 6)')
|
85
|
+
end
|
86
|
+
|
87
|
+
db2 = Extralite::Database.new(':memory:')
|
88
|
+
db2.execute('create table if not exists t (x integer primary key, y, z)')
|
89
|
+
|
90
|
+
changeset.apply(db2)
|
91
|
+
|
92
|
+
assert_equal [
|
93
|
+
{ x: 1, y: 2, z: 3 },
|
94
|
+
{ x: 4, y: 5, z: 6 }
|
95
|
+
], db2.query('select * from t')
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_invert
|
99
|
+
changeset = Extralite::Changeset.new
|
100
|
+
|
101
|
+
changeset.track(@db, [:t]) do
|
102
|
+
@db.execute('insert into t values (1, 2, 3)')
|
103
|
+
@db.execute('insert into t values (4, 5, 6)')
|
104
|
+
end
|
105
|
+
|
106
|
+
db2 = Extralite::Database.new(':memory:')
|
107
|
+
db2.execute('create table if not exists t (x integer primary key, y, z)')
|
108
|
+
|
109
|
+
changeset.apply(db2)
|
110
|
+
|
111
|
+
assert_equal [
|
112
|
+
{ x: 1, y: 2, z: 3 },
|
113
|
+
{ x: 4, y: 5, z: 6 }
|
114
|
+
], db2.query('select * from t')
|
115
|
+
|
116
|
+
db2.execute('insert into t values (7, 8, 9)')
|
117
|
+
inverted = changeset.invert
|
118
|
+
|
119
|
+
assert_kind_of Extralite::Changeset, inverted
|
120
|
+
refute_equal inverted, changeset
|
121
|
+
|
122
|
+
assert_equal [
|
123
|
+
[:delete, 't', [1, 2, 3], nil],
|
124
|
+
[:delete, 't', [4, 5, 6], nil],
|
125
|
+
], inverted.to_a
|
126
|
+
|
127
|
+
inverted.apply(@db)
|
128
|
+
assert_equal [], @db.query('select * from t')
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_blob
|
132
|
+
changeset = Extralite::Changeset.new
|
133
|
+
assert_equal '', changeset.to_blob
|
134
|
+
|
135
|
+
changeset.track(@db, [:t]) do
|
136
|
+
@db.execute('insert into t values (1, 2, 3)')
|
137
|
+
@db.execute('insert into t values (4, 5, 6)')
|
138
|
+
end
|
139
|
+
|
140
|
+
blob = changeset.to_blob
|
141
|
+
assert_kind_of String, blob
|
142
|
+
assert_equal Encoding::ASCII_8BIT, blob.encoding
|
143
|
+
assert !blob.empty?
|
144
|
+
|
145
|
+
c2 = Extralite::Changeset.new
|
146
|
+
c2.load(blob)
|
147
|
+
assert_equal c2.to_blob, blob
|
148
|
+
|
149
|
+
assert_equal [
|
150
|
+
[:insert, 't', nil, [1, 2, 3]],
|
151
|
+
[:insert, 't', nil, [4, 5, 6]]
|
152
|
+
], c2.to_a
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_empty_blob
|
156
|
+
changeset = Extralite::Changeset.new
|
157
|
+
changeset.load('')
|
158
|
+
|
159
|
+
assert_raises(Extralite::Error) { changeset.to_a }
|
160
|
+
end
|
161
|
+
end
|