foobara-redis-crud-driver 0.0.3 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db6c81dfe5009f3f778ec4f05b6bd0d6809718ba126fe0dba259c3666e344cd5
4
- data.tar.gz: e30d4ff3154a4396106550c5ff8c46c00e160b62ec54ec8f93c74cb50d72d850
3
+ metadata.gz: 5eb2adfa4e202e290ad4b2c85fec629e93fa1a7f214005e245aa425c2d1af906
4
+ data.tar.gz: 9818c7e4f4dcde783028afd1eb64a5d20a0d95dba4bfe6b41af961a127fcdb50
5
5
  SHA512:
6
- metadata.gz: 78efec1418b1fca8b349719f3fd4e7777f09460577bb9e1f12e38246a48f35cd65e1957f077c8e64147bbcd68c005c3a0fb9c12dc87d6711904b18863d7d4e55
7
- data.tar.gz: 60547f0d67c390429179ad01a30e6338667ffe7cd6236fee88ae3bd061fa9ae9a5a3b36a221ccc11b435be29c15a6815134f276a967effebe0499bb2bf9a300f
6
+ metadata.gz: a647944c1560caba524ac82c5a34f0c6f99d96fa1b5b949cc896245f2eeb9e83b647f62f52d9e3ee377b172a49023cb1b74a60c7d3eae56e67bb58bc812a51ee
7
+ data.tar.gz: a5d4f012659d33094e54c2dac09692cbdb67653013262fd43a64d0f13ee25d078b5443ac28db9881bdb0ce04c507cbfd334184edbfadb7ff218b086c9e541519
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.2.2
1
+ 3.4.3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.0.5] - 2025-05-15
2
+
3
+ - Support string primary keys
4
+
5
+ ## [0.0.4] - 2025-01-07
6
+
7
+ - Bump Ruby to 3.4.1
8
+
1
9
  ## [0.0.3] - 2024-11-30
2
10
 
3
11
  - Make use of default crud driver methods
@@ -39,19 +39,13 @@ 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
 
@@ -83,6 +77,7 @@ module Foobara
83
77
  end
84
78
  end
85
79
 
80
+ # TODO: move this up to base class as a default
86
81
  def find!(record_id)
87
82
  attributes = find(record_id)
88
83
 
@@ -112,7 +107,7 @@ module Foobara
112
107
 
113
108
  # TODO: use redis.multi here
114
109
  redis.hset(record_key_prefix(record_id), attributes)
115
- redis.zadd(primary_keys_index_key, record_id, record_id)
110
+ redis.zadd(primary_keys_index_key, id_to_score(record_id), record_id)
116
111
  find(record_id)
117
112
  end
118
113
 
@@ -201,20 +196,57 @@ module Foobara
201
196
  def batches_of_primary_keys
202
197
  limit = [0, 50]
203
198
 
204
- lower_bound = 0
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
205
208
 
206
209
  Enumerator.new do |yielder|
207
210
  loop do
208
- batch = redis.zrangebyscore(primary_keys_index_key, lower_bound, "+inf", limit:)
209
-
211
+ batch = redis.send(command, primary_keys_index_key, lower_bound, upper_bound, limit:)
210
212
  break if batch.empty?
211
213
 
212
214
  yielder << batch
213
215
 
214
- lower_bound = batch.last.to_i + 1
216
+ lower_bound = if string_primary_key?
217
+ "(#{batch.last}"
218
+ else
219
+ id_to_score(batch.last) + 1
220
+ end
215
221
  end
216
222
  end.lazy
217
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
218
250
  end
219
251
  end
220
252
  end
metadata CHANGED
@@ -1,29 +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.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-11-30 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: foobara
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - ">="
16
+ - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '0'
18
+ version: 0.0.125
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - ">="
23
+ - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '0'
25
+ version: 0.0.125
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: redis
29
28
  requirement: !ruby/object:Gem::Requirement
@@ -60,7 +59,6 @@ metadata:
60
59
  source_code_uri: https://github.com/foobara/redis-crud-driver
61
60
  changelog_uri: https://github.com/foobara/redis-crud-driver/blob/main/CHANGELOG.md
62
61
  rubygems_mfa_required: 'true'
63
- post_install_message:
64
62
  rdoc_options: []
65
63
  require_paths:
66
64
  - lib
@@ -69,15 +67,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
67
  requirements:
70
68
  - - ">="
71
69
  - !ruby/object:Gem::Version
72
- version: 3.2.2
70
+ version: 3.4.0
73
71
  required_rubygems_version: !ruby/object:Gem::Requirement
74
72
  requirements:
75
73
  - - ">="
76
74
  - !ruby/object:Gem::Version
77
75
  version: '0'
78
76
  requirements: []
79
- rubygems_version: 3.5.23
80
- signing_key:
77
+ rubygems_version: 3.6.7
81
78
  specification_version: 4
82
79
  summary: Provides support for entity CRUD in Redis for Foobara
83
80
  test_files: []