frozen_record 0.26.0 → 0.26.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/benchmark/querying +7 -0
- data/lib/frozen_record/base.rb +26 -1
- data/lib/frozen_record/scope.rb +7 -2
- data/lib/frozen_record/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: 4e4a597e4419873da69776c887c5ef35c812f785493cd9597d3d3ced891578ab
|
4
|
+
data.tar.gz: d46b86085ceeee261b39a281aab1c62a2551e872ad1f4696e8a7325b7cfa9a7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e68a5dfb1d888de4f6dc72bb42ffdc1c08af87229b7bd0dcf107d1da9b48ef5b948adea5652b132cb497a1a8c15b513aa7ba8beea7c863b06f19de14ae02865
|
7
|
+
data.tar.gz: f787b5072efd3997fb41942c1d9b6014ee872d6faec12a4c5a77ef489a7039ed980987bbf4102ed7d9c5cd2b296e49c1bd6a25f578559969d200d875d6cdf877
|
data/CHANGELOG.md
CHANGED
data/benchmark/querying
CHANGED
@@ -23,6 +23,13 @@ class LargeCountry < Country
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
LargeCountry.eager_load!
|
27
|
+
|
28
|
+
puts "=== unique index lookup ==="
|
29
|
+
Benchmark.ips do |x|
|
30
|
+
x.report('pk lookup') { LargeCountry.find_by(name: "Canada1") }
|
31
|
+
end
|
32
|
+
|
26
33
|
puts "=== simple scalar match ==="
|
27
34
|
Benchmark.ips do |x|
|
28
35
|
x.report('simple') { LargeCountry.nato.size }
|
data/lib/frozen_record/base.rb
CHANGED
@@ -107,7 +107,7 @@ module FrozenRecord
|
|
107
107
|
store[:scope] = scope
|
108
108
|
end
|
109
109
|
|
110
|
-
delegate :each, :
|
110
|
+
delegate :each, :find_each, :where, :first, :first!, :last, :last!,
|
111
111
|
:pluck, :ids, :order, :limit, :offset, :minimum, :maximum, :average, :sum, :count,
|
112
112
|
to: :current_scope
|
113
113
|
|
@@ -123,6 +123,31 @@ module FrozenRecord
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
+
def find_by_id(id)
|
127
|
+
find_by(primary_key => id)
|
128
|
+
end
|
129
|
+
|
130
|
+
def find(id)
|
131
|
+
raise RecordNotFound, "Can't lookup record without ID" unless id
|
132
|
+
find_by(primary_key => id) or raise RecordNotFound, "Couldn't find a record with ID = #{id.inspect}"
|
133
|
+
end
|
134
|
+
|
135
|
+
def find_by(criterias)
|
136
|
+
if criterias.size == 1
|
137
|
+
criterias.each do |attribute, value|
|
138
|
+
attribute = attribute.to_s
|
139
|
+
if index = index_definitions[attribute]
|
140
|
+
return index.lookup(value).first
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
current_scope.find_by(criterias)
|
145
|
+
end
|
146
|
+
|
147
|
+
def find_by!(criterias)
|
148
|
+
find_by(criterias) or raise RecordNotFound, "No record matched"
|
149
|
+
end
|
150
|
+
|
126
151
|
def add_index(attribute, unique: false)
|
127
152
|
index = unique ? UniqueIndex.new(self, attribute) : Index.new(self, attribute)
|
128
153
|
self.index_definitions = index_definitions.merge(index.attribute => index).freeze
|
data/lib/frozen_record/scope.rb
CHANGED
@@ -34,12 +34,17 @@ module FrozenRecord
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def find_by_id(id)
|
37
|
-
|
37
|
+
find_by(@klass.primary_key => id)
|
38
38
|
end
|
39
39
|
|
40
40
|
def find(id)
|
41
41
|
raise RecordNotFound, "Can't lookup record without ID" unless id
|
42
|
-
|
42
|
+
|
43
|
+
scope = self
|
44
|
+
if @limit || @offset
|
45
|
+
scope = limit(nil).offset(nil)
|
46
|
+
end
|
47
|
+
scope.find_by_id(id) or raise RecordNotFound, "Couldn't find a record with ID = #{id.inspect}"
|
43
48
|
end
|
44
49
|
|
45
50
|
def find_by(criterias)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frozen_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.26.
|
4
|
+
version: 0.26.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean Boussier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|