rom-sql 2.4.0 → 2.5.0

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
  SHA256:
3
- metadata.gz: 3c85bad1904593cc81ceecc277c2dd0bdebbe452815f366b55a016d9b4dc9e0c
4
- data.tar.gz: 716ab6775db7fbcb1e7cf4fe88d109a8a9ee0c66ed905b6cb07a26926ee11c0f
3
+ metadata.gz: a266477f912328221111569376f3dc3a007e2db851d251255279f25a7bbe7b5e
4
+ data.tar.gz: 440673756558a62398d09882dd3a29e76ea2ea21bb6c50c5c5a006a64d22fdf2
5
5
  SHA512:
6
- metadata.gz: ebc1ab0de6e3a30be1d42b0c6abf8e162cefdbf7a8a9bf00eda79689c85b44353cb8b2a30b016f4f0b37ea75206677f67ec1a60833afc344ba898e6ee7fd5e7d
7
- data.tar.gz: fbbd991e67b153dd2899159eb4c3ea6f1aae0682f0496bc1955c368479b78956e15076d41b2a96803791457f01b4ad2b0ed9fdf3161278456cb8386d83b9eb8f
6
+ metadata.gz: b9efce415899ce279306fd604cce634c06cd70c06705cef9826ec990dbcee7f3c9fb70adc2a7bdebda62a6a7e2544aab77b06d5c4e3be3bda9c8083fb724dddd
7
+ data.tar.gz: c784be269b61cfda971a8cc11c8cd0c6f0e4780c21d35c6fc521e7fad38585d59507b77698c3aa8a0f932559704bfba833b54e8506bb0e3fa3fe4620034c4d66
@@ -1,3 +1,18 @@
1
+ ## v2.5.0 2018-06-08
2
+
3
+ ### Added
4
+
5
+ * Support for subqueries in `SELECT` and `WHERE` :tada: (flash-gordon)
6
+ ```ruby
7
+ tasks = relations[:tasks]
8
+ users = relations[:users]
9
+ user_tasks = tasks.where(tasks[:user_id].is(users[:id])
10
+ tasks_count = user_tasks.select { int::count(id) }
11
+ users.select_append(tasks_count.as(:tasks_count))
12
+ ```
13
+
14
+ [Compare v2.4.0...v2.5.0](https://github.com/rom-rb/rom-sql/compare/v2.4.0...v2.5.0)
15
+
1
16
  ## v2.4.0 2018-02-18
2
17
 
3
18
  ### Added
data/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  [gem]: https://rubygems.org/gems/rom-sql
2
2
  [travis]: https://travis-ci.org/rom-rb/rom-sql
3
- [gemnasium]: https://gemnasium.com/rom-rb/rom-sql
4
3
  [codeclimate]: https://codeclimate.com/github/rom-rb/rom-sql
5
4
  [inchpages]: http://inch-ci.org/github/rom-rb/rom-sql
6
5
 
@@ -8,7 +7,6 @@
8
7
 
9
8
  [![Gem Version](https://badge.fury.io/rb/rom-sql.svg)][gem]
10
9
  [![Build Status](https://travis-ci.org/rom-rb/rom-sql.svg?branch=master)][travis]
11
- [![Dependency Status](https://gemnasium.com/rom-rb/rom-sql.svg)][gemnasium]
12
10
  [![Code Climate](https://codeclimate.com/github/rom-rb/rom-sql/badges/gpa.svg)][codeclimate]
13
11
  [![Test Coverage](https://codeclimate.com/github/rom-rb/rom-sql/badges/coverage.svg)][codeclimate]
14
12
  [![Inline docs](http://inch-ci.org/github/rom-rb/rom-sql.svg?branch=master)][inchpages]
@@ -40,13 +40,13 @@ module ROM
40
40
  'numrange', SQL::Types::Coercible::Int
41
41
  ),
42
42
  tsrange: Sequel::Postgres::PGRange::Parser.new(
43
- 'tsrange', SQL::Types::Form::Time
43
+ 'tsrange', ::Time.method(:parse)
44
44
  ),
45
45
  tstzrange: Sequel::Postgres::PGRange::Parser.new(
46
- 'tstzrange', SQL::Types::Form::Time
46
+ 'tstzrange', ::Time.method(:parse)
47
47
  ),
48
48
  daterange: Sequel::Postgres::PGRange::Parser.new(
49
- 'daterange', SQL::Types::Form::Date
49
+ 'daterange', ::Date.method(:parse)
50
50
  )
51
51
  }.freeze
52
52
 
@@ -10,7 +10,7 @@ module ROM
10
10
  # Return a string literal that will be directly used in an SQL statement or query
11
11
  #
12
12
  # @example
13
- # users.select { `FOO`.as(:foo) }.first
13
+ # users.select { `'FOO'`.as(:foo) }.first
14
14
  # # => { :foo => "FOO" }
15
15
  #
16
16
  # @param [String] value A string object
@@ -155,7 +155,7 @@ module ROM
155
155
  #
156
156
  # @api public
157
157
  def pluck(name)
158
- map(name)
158
+ select(name).map(name)
159
159
  end
160
160
 
161
161
  # Rename columns in a relation
@@ -937,6 +937,24 @@ module ROM
937
937
  dataset.as_hash(attribute)
938
938
  end
939
939
 
940
+ # Turn a relation into a subquery. Can be used
941
+ # for selecting a column with a subquery or
942
+ # restricting the result set with a IN (SELECT ...) condtion.
943
+ #
944
+ # @example adding number of user tasks
945
+ # tasks = relations[:tasks]
946
+ # users = relations[:users]
947
+ # user_tasks = tasks.where(tasks[:user_id].is(users[:id])
948
+ # tasks_count = user_tasks.select { int::count(id) }
949
+ # users.select_append(tasks_count.as(:tasks_count))
950
+ #
951
+ # @return [SQL::Attribute]
952
+ def query
953
+ attr = schema.to_a[0]
954
+ subquery = schema.project(attr).(self).dataset.unordered
955
+ SQL::Attribute[attr.type].meta(sql_expr: subquery)
956
+ end
957
+
940
958
  private
941
959
 
942
960
  # Build a locking clause
@@ -1,5 +1,5 @@
1
1
  module ROM
2
2
  module SQL
3
- VERSION = '2.4.0'.freeze
3
+ VERSION = '2.5.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rom-sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-18 00:00:00.000000000 Z
11
+ date: 2018-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -239,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
239
  version: '0'
240
240
  requirements: []
241
241
  rubyforge_project:
242
- rubygems_version: 2.7.4
242
+ rubygems_version: 2.7.6
243
243
  signing_key:
244
244
  specification_version: 4
245
245
  summary: SQL databases support for ROM