mongery 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c654aa684e186267a8ad90f66b57a7c000e2529b
4
- data.tar.gz: 31e9d9fab939af0b876f68782ae44950da8ecda6
3
+ metadata.gz: 3aeb64347aabfea21e8a23c2160e10256404f948
4
+ data.tar.gz: 60d53661a827f430c4dfe6bd34466deab7b1168f
5
5
  SHA512:
6
- metadata.gz: 627d0288cfc9409bd7f00f374b2a50ec0c6acdbaaaac90e47855a0cf57b99b427e24cec0a2fd6b485131a56b3b8f507c02c221db2c2afe9552960543d46fc0fd
7
- data.tar.gz: 5768a7da04168ee460e1e88cdb05a28d576d46cbd422819ffc5370a2a6569b6ba14cdd2958a8f29291e3a2c1878c9c130edf6fd998e24efdb9c96531b07c8518
6
+ metadata.gz: 6e3a644c5a6c6409c2923f7c1a228fd5f287011f94134b460b4adcff86076fecc4ce990fd0d38e04263b61e6166627f739dbb73c558af6018371677eef40c858
7
+ data.tar.gz: 2112b7028f0c874bc3e8024d668ae0b254e34116ca1464b8fe4fecc09c8ac5fd6ae33e61e3ef9f874218391f019fd328b7eae02f2321608b28cfeb24d1fa47c3
@@ -1,3 +1,6 @@
1
+ ## 1.0.3 (2015/01/09)
2
+ - Support index method to create expression indexes
3
+
1
4
  ## 1.0.2 (2015/01/09)
2
5
  - Support mapped_properties to map system columns on Postgres
3
6
  - Look up all values using string keys rather than symbol. Make sure you use indifferent_access, or stringify_key before passing the value hash to Mongery
@@ -29,6 +29,10 @@ module Mongery
29
29
  def insert(*args)
30
30
  Query.new(table, schema, mapped_properties).insert(*args)
31
31
  end
32
+
33
+ def index(*args)
34
+ Query.new(table, schema, mapped_properties).index(*args)
35
+ end
32
36
  end
33
37
 
34
38
  class Query
@@ -81,6 +85,18 @@ module Mongery
81
85
  self
82
86
  end
83
87
 
88
+ def sql_json_exp(col)
89
+ if schema && numeric?(col)
90
+ sql_json_path(col) + "::numeric"
91
+ else
92
+ sql_json_path(col)
93
+ end
94
+ end
95
+
96
+ def index(col)
97
+ Arel.sql(%Q[CREATE INDEX "#{table.name}_#{col}_idx" ON "#{table.name}" ((#{sql_json_exp(col)}))])
98
+ end
99
+
84
100
  def mapped_values(args)
85
101
  pairs = []
86
102
  mapped_properties.each do |key, column|
@@ -288,6 +304,11 @@ module Mongery
288
304
  end
289
305
  end
290
306
 
307
+ def numeric?(col)
308
+ type = schema.column_type(col.to_s)
309
+ ["number", "integer"].include?(type)
310
+ end
311
+
291
312
  def compare_schema(col, val, type, op)
292
313
  case type
293
314
  when "string"
@@ -1,3 +1,3 @@
1
1
  module Mongery
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongery
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tatsuhiko Miyagawa