foobara-redis-crud-driver 0.0.4 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8a81120a1e087040686a18fb873d84b701d578708b59cb14d6c842206f56d3e
4
- data.tar.gz: 35ef909f9222826cc36bc73e585f91d54235b4ff10dae6cb3c6182c85982d96a
3
+ metadata.gz: a54546ecb7497876846a64f0306c99630365e16051abc72b98af54332f51921b
4
+ data.tar.gz: 1c8acd4863e4ed466a2a4e90b49050c4cd5d6aa689c981c9d98538e064ab82a5
5
5
  SHA512:
6
- metadata.gz: 60fa11bed5950a363f2a08bf3e789175c012b24614703cb82a70bde0ec63ab8f115323e79f6b4de93ad9b0f357220774ca6ca50d96f47b0b1928358587c7e4ef
7
- data.tar.gz: 385faf75c6a4a8de419ab96eec05c995cd90acd96a649da7afdd5cfd7c683bc4138b35e39c1954fe9a48e28cfe073b68ba08df3cdfb9176b31f43efc3eeda02d
6
+ metadata.gz: 1332d039107309e3743b6289ed84315719eeecb760d4ddd6c7a4bdbbcb66d0faaf8fc853c8b8aeddfa440cf74f7565594652b254388474527151d8482a9e2a05
7
+ data.tar.gz: f971e1135cf1bacb5a15f5c0ee6c4cb45f0247202793e8c453f5c34f8b7d56659dd25c7bae2c90a1118b99c22728bdc53fa378cd2b761210091d27bcfc5e42be
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.4.1
1
+ 3.4.3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.0.6] - 2025-06-16
2
+
3
+ - Move crud-driver-specific specs to foobara-crud-driver-spec-helpers gem
4
+
5
+ ## [0.0.5] - 2025-05-15
6
+
7
+ - Support string primary keys
8
+
1
9
  ## [0.0.4] - 2025-01-07
2
10
 
3
11
  - Bump Ruby to 3.4.1
@@ -39,23 +39,17 @@ module Foobara
39
39
  end
40
40
 
41
41
  class Table < Persistence::EntityAttributesCrudDriver::Table
42
- def initialize(...)
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
 
58
- def all
52
+ def all(page_size: nil)
59
53
  Enumerator.new do |yielder|
60
54
  batches_of_primary_keys.each do |batch|
61
55
  raw_records = redis.pipelined do |p|
@@ -83,17 +77,6 @@ module Foobara
83
77
  end
84
78
  end
85
79
 
86
- # TODO: move this up to base class as a default
87
- def find!(record_id)
88
- attributes = find(record_id)
89
-
90
- unless attributes
91
- raise CannotFindError.new(record_id, "does not exist")
92
- end
93
-
94
- attributes
95
- end
96
-
97
80
  def insert(attributes)
98
81
  attributes = Util.deep_dup(attributes)
99
82
 
@@ -113,7 +96,7 @@ module Foobara
113
96
 
114
97
  # TODO: use redis.multi here
115
98
  redis.hset(record_key_prefix(record_id), attributes)
116
- redis.zadd(primary_keys_index_key, record_id, record_id)
99
+ redis.zadd(primary_keys_index_key, id_to_score(record_id), record_id)
117
100
  find(record_id)
118
101
  end
119
102
 
@@ -202,20 +185,57 @@ module Foobara
202
185
  def batches_of_primary_keys
203
186
  limit = [0, 50]
204
187
 
205
- lower_bound = 0
188
+ if string_primary_key?
189
+ lower_bound = "-"
190
+ upper_bound = "+"
191
+ command = :zrangebylex
192
+ else
193
+ lower_bound = 0
194
+ upper_bound = "+inf"
195
+ command = :zrangebyscore
196
+ end
206
197
 
207
198
  Enumerator.new do |yielder|
208
199
  loop do
209
- batch = redis.zrangebyscore(primary_keys_index_key, lower_bound, "+inf", limit:)
210
-
200
+ batch = redis.send(command, primary_keys_index_key, lower_bound, upper_bound, limit:)
211
201
  break if batch.empty?
212
202
 
213
203
  yielder << batch
214
204
 
215
- lower_bound = batch.last.to_i + 1
205
+ lower_bound = if string_primary_key?
206
+ "(#{batch.last}"
207
+ else
208
+ id_to_score(batch.last) + 1
209
+ end
216
210
  end
217
211
  end.lazy
218
212
  end
213
+
214
+ def id_to_score(id)
215
+ if string_primary_key?
216
+ 0
217
+ else
218
+ id.to_i
219
+ end
220
+ end
221
+
222
+ def string_primary_key?
223
+ primary_key_symbol == :string
224
+ end
225
+
226
+ def primary_key_symbol
227
+ return @primary_key_symbol if defined?(@primary_key_symbol)
228
+
229
+ type_symbol = entity_class.primary_key_type.type_symbol
230
+
231
+ unless [:integer, :string].include?(type_symbol)
232
+ # :nocov:
233
+ raise "Only integer and string primary keys are supported for now"
234
+ # :nocov:
235
+ end
236
+
237
+ @primary_key_symbol = type_symbol
238
+ end
219
239
  end
220
240
  end
221
241
  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
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-07 00:00:00.000000000 Z
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: '0'
18
+ version: 0.0.131
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: '0'
25
+ version: 0.0.131
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: redis
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -61,7 +61,6 @@ metadata:
61
61
  rubygems_mfa_required: 'true'
62
62
  rdoc_options: []
63
63
  require_paths:
64
- - lib
65
64
  - src
66
65
  required_ruby_version: !ruby/object:Gem::Requirement
67
66
  requirements:
@@ -74,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
73
  - !ruby/object:Gem::Version
75
74
  version: '0'
76
75
  requirements: []
77
- rubygems_version: 3.6.2
76
+ rubygems_version: 3.6.9
78
77
  specification_version: 4
79
78
  summary: Provides support for entity CRUD in Redis for Foobara
80
79
  test_files: []