mystic 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mystic/model.rb +7 -5
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 352832d5a99d22c0f360346f660e2c6ce234f4b3
4
- data.tar.gz: eaad20d1ca2059c66dce838f12cb5e5f0cd0705f
3
+ metadata.gz: e1e592ee5ecc01ba11d3504a180f611d0edc5750
4
+ data.tar.gz: 426a67b8cd7c0ffd8e615db88edcdffd332191d9
5
5
  SHA512:
6
- metadata.gz: 29b0c4ff3ffc55ab14920124e11c9af2157293af0d614cf6acb2634e8e37f74278a0d3eeda9469724cccb652c9a1a44ef4781a2877961858a380baf12cf9664f
7
- data.tar.gz: df56f54b96579764df117822fc6e035562b5bb69a52df38899ae3e71e66ebdd44b61c2fadd1880802dd79a67438f1088de0b06cc4028f34550b560e84b6126f1
6
+ metadata.gz: adaaf10689933dd6a2bf7536069f9dd49a23eebcb9a9a8e2edf92cf65e7e12003f96c4e51285542613706272cd48432bba5150a355a577f7d38e17e4bdaf4d16
7
+ data.tar.gz: 63471fe4db1e70702dd917d566911ecfcc97bf4db8d8b2c0e914752e55688cced0812c8b7e57fd1be323e3eff3496eabf407cd29194ae3b582a2ddb747100e53
@@ -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))" unless op == "INSERT"
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mystic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathaniel Symer