foobara-redis-crud-driver 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/CHANGELOG.md +4 -0
- data/src/foobara/redis_crud_driver.rb +43 -12
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5eb2adfa4e202e290ad4b2c85fec629e93fa1a7f214005e245aa425c2d1af906
|
4
|
+
data.tar.gz: 9818c7e4f4dcde783028afd1eb64a5d20a0d95dba4bfe6b41af961a127fcdb50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a647944c1560caba524ac82c5a34f0c6f99d96fa1b5b949cc896245f2eeb9e83b647f62f52d9e3ee377b172a49023cb1b74a60c7d3eae56e67bb58bc812a51ee
|
7
|
+
data.tar.gz: a5d4f012659d33094e54c2dac09692cbdb67653013262fd43a64d0f13ee25d078b5443ac28db9881bdb0ce04c507cbfd334184edbfadb7ff218b086c9e541519
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.4.
|
1
|
+
3.4.3
|
data/CHANGELOG.md
CHANGED
@@ -39,19 +39,13 @@ module Foobara
|
|
39
39
|
end
|
40
40
|
|
41
41
|
class Table < Persistence::EntityAttributesCrudDriver::Table
|
42
|
-
def
|
43
|
-
super
|
44
|
-
|
42
|
+
def get_id
|
45
43
|
unless entity_class.primary_key_type.type_symbol == :integer
|
46
|
-
# TODO: when primary key is a string such as a uuid we should
|
47
|
-
# probably set the score to 0 and use other methods. But not interested in implementing that stuff now.
|
48
44
|
# :nocov:
|
49
45
|
raise "Only integer primary keys are supported for now"
|
50
46
|
# :nocov:
|
51
47
|
end
|
52
|
-
end
|
53
48
|
|
54
|
-
def get_id
|
55
49
|
redis.incr(sequence_key)
|
56
50
|
end
|
57
51
|
|
@@ -113,7 +107,7 @@ module Foobara
|
|
113
107
|
|
114
108
|
# TODO: use redis.multi here
|
115
109
|
redis.hset(record_key_prefix(record_id), attributes)
|
116
|
-
redis.zadd(primary_keys_index_key, record_id, record_id)
|
110
|
+
redis.zadd(primary_keys_index_key, id_to_score(record_id), record_id)
|
117
111
|
find(record_id)
|
118
112
|
end
|
119
113
|
|
@@ -202,20 +196,57 @@ module Foobara
|
|
202
196
|
def batches_of_primary_keys
|
203
197
|
limit = [0, 50]
|
204
198
|
|
205
|
-
|
199
|
+
if string_primary_key?
|
200
|
+
lower_bound = "-"
|
201
|
+
upper_bound = "+"
|
202
|
+
command = :zrangebylex
|
203
|
+
else
|
204
|
+
lower_bound = 0
|
205
|
+
upper_bound = "+inf"
|
206
|
+
command = :zrangebyscore
|
207
|
+
end
|
206
208
|
|
207
209
|
Enumerator.new do |yielder|
|
208
210
|
loop do
|
209
|
-
batch = redis.
|
210
|
-
|
211
|
+
batch = redis.send(command, primary_keys_index_key, lower_bound, upper_bound, limit:)
|
211
212
|
break if batch.empty?
|
212
213
|
|
213
214
|
yielder << batch
|
214
215
|
|
215
|
-
lower_bound =
|
216
|
+
lower_bound = if string_primary_key?
|
217
|
+
"(#{batch.last}"
|
218
|
+
else
|
219
|
+
id_to_score(batch.last) + 1
|
220
|
+
end
|
216
221
|
end
|
217
222
|
end.lazy
|
218
223
|
end
|
224
|
+
|
225
|
+
def id_to_score(id)
|
226
|
+
if string_primary_key?
|
227
|
+
0
|
228
|
+
else
|
229
|
+
id.to_i
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def string_primary_key?
|
234
|
+
primary_key_symbol == :string
|
235
|
+
end
|
236
|
+
|
237
|
+
def primary_key_symbol
|
238
|
+
return @primary_key_symbol if defined?(@primary_key_symbol)
|
239
|
+
|
240
|
+
type_symbol = entity_class.primary_key_type.type_symbol
|
241
|
+
|
242
|
+
unless [:integer, :string].include?(type_symbol)
|
243
|
+
# :nocov:
|
244
|
+
raise "Only integer and string primary keys are supported for now"
|
245
|
+
# :nocov:
|
246
|
+
end
|
247
|
+
|
248
|
+
@primary_key_symbol = type_symbol
|
249
|
+
end
|
219
250
|
end
|
220
251
|
end
|
221
252
|
end
|
metadata
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foobara-redis-crud-driver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Georgi
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: foobara
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
15
15
|
requirements:
|
16
|
-
- - "
|
16
|
+
- - "~>"
|
17
17
|
- !ruby/object:Gem::Version
|
18
|
-
version:
|
18
|
+
version: 0.0.125
|
19
19
|
type: :runtime
|
20
20
|
prerelease: false
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
22
22
|
requirements:
|
23
|
-
- - "
|
23
|
+
- - "~>"
|
24
24
|
- !ruby/object:Gem::Version
|
25
|
-
version:
|
25
|
+
version: 0.0.125
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: redis
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
requirements: []
|
77
|
-
rubygems_version: 3.6.
|
77
|
+
rubygems_version: 3.6.7
|
78
78
|
specification_version: 4
|
79
79
|
summary: Provides support for entity CRUD in Redis for Foobara
|
80
80
|
test_files: []
|