mystic 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mystic/model.rb +7 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1e592ee5ecc01ba11d3504a180f611d0edc5750
|
4
|
+
data.tar.gz: 426a67b8cd7c0ffd8e615db88edcdffd332191d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adaaf10689933dd6a2bf7536069f9dd49a23eebcb9a9a8e2edf92cf65e7e12003f96c4e51285542613706272cd48432bba5150a355a577f7d38e17e4bdaf4d16
|
7
|
+
data.tar.gz: 63471fe4db1e70702dd917d566911ecfcc97bf4db8d8b2c0e914752e55688cced0812c8b7e57fd1be323e3eff3496eabf407cd29194ae3b582a2ddb747100e53
|
data/lib/mystic/model.rb
CHANGED
@@ -14,11 +14,11 @@ module Mystic
|
|
14
14
|
sym_opts = opts.symbolize
|
15
15
|
|
16
16
|
sql = sym_opts[:sql] || "SELECT 1"
|
17
|
+
op = sql.split(/\s+/,2).first.upcase
|
17
18
|
return_rows = sym_opts[:return_rows] || false
|
18
19
|
return_json = sym_opts[:return_json] || false
|
19
20
|
return_rows = true if return_json
|
20
|
-
|
21
|
-
op = sql.split(/\s+/,2).first
|
21
|
+
plural = opts[:plural] && op != "INSERT"
|
22
22
|
|
23
23
|
sql << " RETURNING #{visible_cols*','}" if return_rows && op != "SELECT"
|
24
24
|
|
@@ -27,7 +27,8 @@ module Mystic
|
|
27
27
|
if return_json
|
28
28
|
s << "WITH res AS (#{sql}) SELECT"
|
29
29
|
s << "row_to_json(res)" if op == "INSERT"
|
30
|
-
s << "array_to_json(array_agg(res))"
|
30
|
+
s << "array_to_json(array_agg(res))" if plural
|
31
|
+
s << "row_to_json(res)" unless plural
|
31
32
|
s << "AS #{Mystic::JSON_COL}"
|
32
33
|
s << "FROM res"
|
33
34
|
else
|
@@ -45,7 +46,7 @@ module Mystic
|
|
45
46
|
sym_opts = opts.symbolize
|
46
47
|
count = sym_opts[:count] || 0
|
47
48
|
where = params.sqlize
|
48
|
-
|
49
|
+
|
49
50
|
sql = []
|
50
51
|
sql << "SELECT #{visible_cols*','} FROM #{table_name}"
|
51
52
|
sql << "WHERE #{where*' AND '}" if where.count > 0
|
@@ -54,7 +55,8 @@ module Mystic
|
|
54
55
|
wrapper_sql(
|
55
56
|
:sql => sql.join(' '),
|
56
57
|
:return_rows => true,
|
57
|
-
:return_json => sym_opts[:return_json] && Mystic.adapter.json_supported
|
58
|
+
:return_json => sym_opts[:return_json] && Mystic.adapter.json_supported?,
|
59
|
+
:plural => count > 1
|
58
60
|
)
|
59
61
|
end
|
60
62
|
|