hugg-orm 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hugg_orm/persistence.rb +22 -3
- data/lib/hugg_orm/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f02a26d1a25e02eadcf890ea57f34aa326fff71e
|
4
|
+
data.tar.gz: 1f57e959f8f038e9a742eca9bb58d3de5b9089fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d738cb17628d732da74012a9c12d39fe81ccbc04e7e6529f21b190ca29ec0c7095f271a90b58b9849db68709c5f4d78fcbd98e8092f6d10d90a741f483807c3
|
7
|
+
data.tar.gz: 5886ae7a88c7142d43749bc5e8f87c91f7ad7ad9551b1b26e91c31f5c0581062124d3f86708f171ed2b9704a0d1c958b02034b3b5adda8594f01b5db42fea853
|
data/lib/hugg_orm/persistence.rb
CHANGED
@@ -17,7 +17,7 @@ module HuggORM
|
|
17
17
|
|
18
18
|
def primary_key(primary_key = nil)
|
19
19
|
self._primary_key = primary_key unless primary_key.nil?
|
20
|
-
self._primary_key
|
20
|
+
self._primary_key ||= "data->>'#{key_field}'"
|
21
21
|
end
|
22
22
|
|
23
23
|
def key_field(key_field = nil)
|
@@ -36,7 +36,12 @@ module HuggORM
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def find(id)
|
39
|
-
where("#{primary_key} = ?", [id]).select.first
|
39
|
+
result = where("#{primary_key} = ?", [id]).select.first
|
40
|
+
new(result) if result
|
41
|
+
end
|
42
|
+
|
43
|
+
def find!(id)
|
44
|
+
find(id) || raise(RecordNotFound.new(id))
|
40
45
|
end
|
41
46
|
|
42
47
|
def all
|
@@ -44,6 +49,10 @@ module HuggORM
|
|
44
49
|
new_collection(results)
|
45
50
|
end
|
46
51
|
|
52
|
+
def delete_all
|
53
|
+
new_query.delete
|
54
|
+
end
|
55
|
+
|
47
56
|
def select(query = nil, where: nil, order: nil, limit: nil, offset: nil)
|
48
57
|
return new_collection(query.select) if query
|
49
58
|
|
@@ -65,10 +74,18 @@ module HuggORM
|
|
65
74
|
new(results.first) unless results.empty?
|
66
75
|
end
|
67
76
|
|
77
|
+
def update!(id, data)
|
78
|
+
update(id, data) || raise(RecordNotFound.new(id))
|
79
|
+
end
|
80
|
+
|
68
81
|
def destroy(id)
|
69
82
|
where("#{primary_key} = ?", [id]).delete > 0
|
70
83
|
end
|
71
84
|
|
85
|
+
def destroy!(id)
|
86
|
+
destroy(id) || raise(RecordNotFound.new(id))
|
87
|
+
end
|
88
|
+
|
72
89
|
def count
|
73
90
|
new_query.count
|
74
91
|
end
|
@@ -158,7 +175,7 @@ module HuggORM
|
|
158
175
|
updated_data = self.class.where("#{self.class.primary_key} = ?", [key]).update(@data, true)
|
159
176
|
|
160
177
|
unless updated_data.empty?
|
161
|
-
@data = updated_data
|
178
|
+
@data = updated_data.first
|
162
179
|
@state = :updated
|
163
180
|
else
|
164
181
|
self.class.new_query.insert(@data)
|
@@ -201,4 +218,6 @@ module HuggORM
|
|
201
218
|
end
|
202
219
|
end
|
203
220
|
end
|
221
|
+
|
222
|
+
class RecordNotFound < StandardError; end
|
204
223
|
end
|
data/lib/hugg_orm/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hugg-orm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Olle Johansson
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-11-
|
13
|
+
date: 2016-11-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: pg
|