query-interface-server 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33c670952d4f59776a596f71ad0c869dee0bb503
|
4
|
+
data.tar.gz: c1b99d139f74ddee12001e1ded36adfda531beb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15a94bb68fe650dadc9b950b3310162855239949a42c810115d74a22b32e739b7320835b68a4edde121b587d57ef9ea8ed365537f2338388c30da04accc5331f
|
7
|
+
data.tar.gz: 28ee4e540bd1a7479e8066f65de1f6259fc2be4aadaef9be2229af1bc987b155f855eda839bd6ab5ed10967d42a880e7d336a6d78881533cd02119bc15aa2010
|
@@ -102,6 +102,12 @@ module QueryInterface
|
|
102
102
|
query.do_query[:count]
|
103
103
|
end
|
104
104
|
|
105
|
+
def update(data)
|
106
|
+
query = self.copy
|
107
|
+
query.add_transformation("update", data)
|
108
|
+
query.do_query[:updated_count]
|
109
|
+
end
|
110
|
+
|
105
111
|
def do_query(add_default_order=true)
|
106
112
|
transformer = Transformations::SequelTransformer.new(self.model.filter)
|
107
113
|
transformer.run(self.transformations, add_default_order)
|
@@ -122,7 +128,6 @@ module QueryInterface
|
|
122
128
|
def method_missing(method_name, *args, &block)
|
123
129
|
evaluate.send(method_name, *args, &block)
|
124
130
|
end
|
125
|
-
|
126
131
|
protected
|
127
132
|
|
128
133
|
def one(which, params = {})
|
@@ -21,6 +21,7 @@ module QueryInterface
|
|
21
21
|
filter: {},
|
22
22
|
with: {},
|
23
23
|
order: {},
|
24
|
+
update: {},
|
24
25
|
})
|
25
26
|
end
|
26
27
|
|
@@ -33,6 +34,7 @@ module QueryInterface
|
|
33
34
|
@query_transformations[:filter].merge!(scope.filters)
|
34
35
|
@query_transformations[:with].merge!(scope.withs)
|
35
36
|
@query_transformations[:order].merge!(scope.orders)
|
37
|
+
@query_transformations[:update].merge!(scope.updates)
|
36
38
|
end
|
37
39
|
|
38
40
|
def query
|
@@ -42,13 +44,14 @@ module QueryInterface
|
|
42
44
|
end
|
43
45
|
|
44
46
|
class TransformationScope
|
45
|
-
attr_accessor :excludes, :filters, :withs, :orders
|
47
|
+
attr_accessor :excludes, :filters, :withs, :orders, :updates
|
46
48
|
|
47
49
|
def initialize
|
48
50
|
self.excludes = {}
|
49
51
|
self.filters = {}
|
50
52
|
self.withs = {}
|
51
53
|
self.orders = {}
|
54
|
+
self.updates = {}
|
52
55
|
end
|
53
56
|
|
54
57
|
def auto_exclude(*names)
|
@@ -67,6 +70,12 @@ module QueryInterface
|
|
67
70
|
end
|
68
71
|
end
|
69
72
|
|
73
|
+
def auto_update(*names)
|
74
|
+
names.each do |name|
|
75
|
+
self.updates[name] = Proc.new {|param| param}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
70
79
|
def exclude(name, &block)
|
71
80
|
self.excludes[name] = block
|
72
81
|
end
|
@@ -75,6 +84,10 @@ module QueryInterface
|
|
75
84
|
self.filters[name] = block
|
76
85
|
end
|
77
86
|
|
87
|
+
def update(name, &block)
|
88
|
+
self.updates[name] = block
|
89
|
+
end
|
90
|
+
|
78
91
|
def with(name, &block)
|
79
92
|
self.withs[name] = block
|
80
93
|
end
|
@@ -33,7 +33,8 @@ module QueryInterface
|
|
33
33
|
constraints = {
|
34
34
|
exclude: :collection, filter: :collection, with: :collection, order: :collection,
|
35
35
|
instance: :collection, context: :instance, map_ids: :collection,
|
36
|
-
paginate: :collection, first: :collection, last: :collection, count: :collection
|
36
|
+
paginate: :collection, first: :collection, last: :collection, count: :collection,
|
37
|
+
update: :collection,
|
37
38
|
}
|
38
39
|
method = transformation['transformation'].to_sym
|
39
40
|
raise UnknownTransformation, "#{method}" unless constraints.has_key?(method)
|
@@ -100,6 +101,21 @@ module QueryInterface
|
|
100
101
|
{count: self.result.count}
|
101
102
|
end
|
102
103
|
|
104
|
+
def schema
|
105
|
+
Hash[self.result.db.schema(self.result.model.table_name)]
|
106
|
+
end
|
107
|
+
|
108
|
+
def update(param)
|
109
|
+
data = Hash[param.map do |field, value|
|
110
|
+
field = field.to_sym
|
111
|
+
[field, self.result.query_transformation(:update, field, value)]
|
112
|
+
end]
|
113
|
+
if not data.include?(:updated_at) and self.schema.include?(:updated_at)
|
114
|
+
data[:updated_at] = DateTime.now
|
115
|
+
end
|
116
|
+
{updated_count: self.result.update(data)}
|
117
|
+
end
|
118
|
+
|
103
119
|
def paginate(param)
|
104
120
|
context = self.default_order
|
105
121
|
{total: context.count, objects: context.paginate(param['page'].to_i, param['per_page'].to_i)}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: query-interface-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Kopecky <andreas.kopecky@radarservices.com>
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-
|
13
|
+
date: 2014-09-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: sequel
|