baby_squeel 1.0.0 → 1.0.1
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 +4 -4
- data/CHANGELOG.md +21 -2
- data/README.md +1 -1
- data/lib/baby_squeel/active_record/where_chain.rb +2 -1
- data/lib/baby_squeel/dsl.rb +19 -1
- data/lib/baby_squeel/nodes.rb +3 -0
- data/lib/baby_squeel/nodes/attribute.rb +2 -2
- data/lib/baby_squeel/nodes/binary.rb +12 -0
- data/lib/baby_squeel/nodes/function.rb +1 -0
- data/lib/baby_squeel/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dccc30465ef9e1b82eed32a0e96c17a5a7fc4e45
|
4
|
+
data.tar.gz: 9a89635d8f91cdd04f6015141de2ab04dda6c224
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c07d0fdbb62c82a2e24575d31c46c7f2e4f6acb87c637d57204c357e1507e682b89f5d996b69ea69580279d9e0afea0fc22c20d3d720bc945c78bccee6ea397
|
7
|
+
data.tar.gz: 82203055a8712beed7bef9651f45863d187ca5518dc0012e1d8ef29cb3c4266ceeeca5835f6fded0498c6130de01a44c47d24526ce5a7b9a0e35b65b9d637459
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,18 @@
|
|
1
|
-
## [
|
1
|
+
## [Unreleased]
|
2
|
+
|
3
|
+
*Nothing yet.*
|
4
|
+
|
5
|
+
## [1.0.1] - 2016-11-07
|
6
|
+
### Added
|
7
|
+
- Add DSL#_ for wrapping expressions in Arel::Node::Grouping. Thanks to [@odedniv].
|
8
|
+
|
9
|
+
### Fixed
|
10
|
+
- Use strings for attribute names like Rails does. Symbols were preventing things like `unscope` from working. Thanks to [@chewi].
|
11
|
+
- `where.has {}` will now accept `nil`.
|
12
|
+
- Arel::Nodes::Function did not previously include Arel::Math, so now you can do math operations on the result of SQL functions.
|
13
|
+
- Arel::Nodes::Binary did not previously include Arel::AliasPredication. Binary nodes can now be aliased using `as`.
|
14
|
+
|
15
|
+
## [1.0.0] - 2016-09-09
|
2
16
|
### Added
|
3
17
|
- Polyamorous. Unfortunately, this *does* monkey-patch Active Record internals, but there just isn't any other reliable way to generate outer joins. Baby Squeel, itself, will still keep monkey patching to an absolute minimum.
|
4
18
|
- Within DSL blocks, you can use `exists` and `not_exists` with Active Record relations. For example: `Post.where.has { exists Post.where(title: 'Fun') }`.`
|
@@ -67,9 +81,14 @@
|
|
67
81
|
### Added
|
68
82
|
- Initial support for selects, orders, wheres, and joins.
|
69
83
|
|
70
|
-
[Unreleased]: https://github.com/rzane/baby_squeel/compare/
|
84
|
+
[Unreleased]: https://github.com/rzane/baby_squeel/compare/v1.0.1...HEAD
|
85
|
+
[1.0.1]: https://github.com/rzane/baby_squeel/compare/v1.0.0...v1.0.1
|
86
|
+
[1.0.0]: https://github.com/rzane/baby_squeel/compare/v0.3.1...v1.0.0
|
71
87
|
[0.3.1]: https://github.com/rzane/baby_squeel/compare/v0.3.0...v0.3.1
|
72
88
|
[0.3.0]: https://github.com/rzane/baby_squeel/compare/v0.2.2...v0.3.0
|
73
89
|
[0.2.2]: https://github.com/rzane/baby_squeel/compare/v0.2.1...v0.2.2
|
74
90
|
[0.2.1]: https://github.com/rzane/baby_squeel/compare/v0.2.0...v0.2.1
|
75
91
|
[0.2.0]: https://github.com/rzane/baby_squeel/compare/v0.1.0...v0.2.0
|
92
|
+
|
93
|
+
[@chewi]: https://github.com/chewi
|
94
|
+
[@odedniv]: https://github.com/odedniv
|
data/README.md
CHANGED
@@ -5,7 +5,8 @@ module BabySqueel
|
|
5
5
|
module WhereChain
|
6
6
|
# Constructs Arel for ActiveRecord::Base#where using the DSL.
|
7
7
|
def has(&block)
|
8
|
-
|
8
|
+
arel = DSL.evaluate(@scope, &block)
|
9
|
+
@scope.where!(arel) unless arel.nil?
|
9
10
|
@scope
|
10
11
|
end
|
11
12
|
end
|
data/lib/baby_squeel/dsl.rb
CHANGED
@@ -24,6 +24,24 @@ module BabySqueel
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
# Create a Grouping node. This allows you to set balanced
|
28
|
+
# pairs of parentheses around your SQL.
|
29
|
+
#
|
30
|
+
# ==== Arguments
|
31
|
+
#
|
32
|
+
# * +expr+ - The expression to group.
|
33
|
+
#
|
34
|
+
# ==== Example
|
35
|
+
# Post.where.has{_([summary, description]).in(...)}
|
36
|
+
# #=> SELECT "posts".* FROM "posts" WHERE ("posts"."summary", "posts"."description") IN (...)"
|
37
|
+
# Post.select{[id, _(Comment.where.has{post_id == posts.id}.selecting{COUNT(id)})]}.as('comment_count')}
|
38
|
+
# #=> SELECT "posts"."id", (SELECT COUNT("comments"."id") FROM "comments" WHERE "comments.post_id" = "posts"."id") AS "comment_count" FROM "posts"
|
39
|
+
#
|
40
|
+
def _(expr)
|
41
|
+
expr = Arel.sql(expr.to_sql) if expr.is_a? ::ActiveRecord::Relation
|
42
|
+
Nodes.wrap Arel::Nodes::Grouping.new(expr)
|
43
|
+
end
|
44
|
+
|
27
45
|
# Create a SQL function. See Arel::Nodes::NamedFunction.
|
28
46
|
#
|
29
47
|
# ==== Arguments
|
@@ -32,7 +50,7 @@ module BabySqueel
|
|
32
50
|
# * +args+ - The arguments to be passed to the SQL function.
|
33
51
|
#
|
34
52
|
# ==== Example
|
35
|
-
# Post.
|
53
|
+
# Post.selecting { func('coalesce', id, 1) }
|
36
54
|
# #=> SELECT COALESCE("posts"."id", 1) FROM "posts"
|
37
55
|
#
|
38
56
|
def func(name, *args)
|
data/lib/baby_squeel/nodes.rb
CHANGED
@@ -2,6 +2,7 @@ require 'baby_squeel/nodes/node'
|
|
2
2
|
require 'baby_squeel/nodes/attribute'
|
3
3
|
require 'baby_squeel/nodes/function'
|
4
4
|
require 'baby_squeel/nodes/grouping'
|
5
|
+
require 'baby_squeel/nodes/binary'
|
5
6
|
|
6
7
|
module BabySqueel
|
7
8
|
module Nodes
|
@@ -14,6 +15,8 @@ module BabySqueel
|
|
14
15
|
Grouping.new(arel)
|
15
16
|
when Arel::Nodes::Function
|
16
17
|
Function.new(arel)
|
18
|
+
when Arel::Nodes::Binary
|
19
|
+
Binary.new(arel)
|
17
20
|
when Arel::Nodes::Node, Arel::Nodes::SqlLiteral
|
18
21
|
Node.new(arel)
|
19
22
|
else
|
data/lib/baby_squeel/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: baby_squeel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ray Zane
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- lib/baby_squeel/join_expression.rb
|
121
121
|
- lib/baby_squeel/nodes.rb
|
122
122
|
- lib/baby_squeel/nodes/attribute.rb
|
123
|
+
- lib/baby_squeel/nodes/binary.rb
|
123
124
|
- lib/baby_squeel/nodes/function.rb
|
124
125
|
- lib/baby_squeel/nodes/grouping.rb
|
125
126
|
- lib/baby_squeel/nodes/node.rb
|