flounder 0.9.5 → 0.9.6
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/Gemfile.lock +33 -0
- data/HISTORY +0 -1
- data/flounder.gemspec +1 -1
- data/lib/flounder/query/base.rb +5 -25
- data/lib/flounder/query/select.rb +5 -1
- data/lib/flounder.rb +0 -5
- data/qed/index.md +10 -7
- metadata +2 -2
- data/flounder-0.9.4.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f8e5bfe7c23126db0ec99a746217736f7e45577
|
4
|
+
data.tar.gz: d69fc270320c38da007f28e1bb8a426e000dd828
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cadf55075780bd232fdae1b7aecf695d6a7772f439a696c04ad93b30562ed9e664d781cdfb0e5a4eb5c411eeaccc015b564b0413a25b59abbd3cdfd588de8b2c
|
7
|
+
data.tar.gz: 24b28594cd17524a688982771b87864bf9de0bb9009aa2b93fedf36b09e5ad3e223432e50a8fa03b4f65a4aea1a36eb1c39085521d43c6a74f806c360a2aa6bd
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
flounder (0.8.1)
|
5
|
+
arel (~> 5, > 5.0.1)
|
6
|
+
connection_pool (~> 2)
|
7
|
+
hashie (~> 3, >= 3.2)
|
8
|
+
pg (> 0.17)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
ae (1.8.2)
|
14
|
+
ansi
|
15
|
+
ansi (1.4.3)
|
16
|
+
arel (5.0.1.20140414130214)
|
17
|
+
brass (1.2.1)
|
18
|
+
connection_pool (2.0.0)
|
19
|
+
facets (2.9.3)
|
20
|
+
hashie (3.2.0)
|
21
|
+
pg (0.17.1)
|
22
|
+
qed (2.9.1)
|
23
|
+
ansi
|
24
|
+
brass
|
25
|
+
facets (>= 2.8)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
ae
|
32
|
+
flounder!
|
33
|
+
qed
|
data/HISTORY
CHANGED
data/flounder.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "flounder"
|
5
|
-
s.version = '0.9.
|
5
|
+
s.version = '0.9.6'
|
6
6
|
s.summary = "Flounder is a way to write SQL simply in Ruby. It deals with everything BUT object relational mapping. "
|
7
7
|
s.email = "kaspar.schiess@technologyastronauts.ch"
|
8
8
|
s.homepage = "https://bitbucket.org/technologyastronauts/oss_flounder"
|
data/lib/flounder/query/base.rb
CHANGED
@@ -31,22 +31,12 @@ module Flounder::Query
|
|
31
31
|
# query.where(:id.noteq => 1) # ... WHERE id != 1
|
32
32
|
#
|
33
33
|
def where *conditions
|
34
|
-
conditions = conditions.dup
|
35
|
-
|
36
|
-
resolve_entity = entity
|
37
|
-
|
38
|
-
# is the first argument an entity? if yes, interpret field names relative
|
39
|
-
# to that entity.
|
40
|
-
if conditions.size > 1 && conditions.first.kind_of?(Flounder::Entity)
|
41
|
-
resolve_entity = conditions.shift
|
42
|
-
end
|
43
|
-
|
44
34
|
# is this a hash? extract the first element
|
45
35
|
if conditions.size == 1 && conditions.first.kind_of?(Hash)
|
46
36
|
conditions = conditions.first
|
47
37
|
|
48
38
|
conditions.each do |k, v|
|
49
|
-
manager.where(transform_tuple(
|
39
|
+
manager.where(transform_tuple(k, v))
|
50
40
|
end
|
51
41
|
return self
|
52
42
|
end
|
@@ -135,31 +125,21 @@ module Flounder::Query
|
|
135
125
|
# * #where
|
136
126
|
# * #on
|
137
127
|
#
|
138
|
-
def transform_tuple
|
128
|
+
def transform_tuple field, value
|
139
129
|
if value.kind_of? Flounder::Field
|
140
130
|
value = value.arel_field
|
141
131
|
end
|
142
132
|
|
143
|
-
if defined?(DataMapper) &&
|
144
|
-
defined?(DataMapper::Query::Operator) &&
|
145
|
-
field.kind_of?(DataMapper::Query::Operator)
|
146
|
-
|
147
|
-
# interop: datamapper hijacks some of our operators, let's reverse this
|
148
|
-
field = Flounder::SymbolExtensions::Modifier.new(
|
149
|
-
field.target, field.operator)
|
150
|
-
end
|
151
|
-
|
152
133
|
case field
|
153
134
|
# covers: :field_a => ...
|
154
135
|
when Symbol
|
155
|
-
join_and_condition_part(entity
|
136
|
+
join_and_condition_part(entity[field].arel_field, value)
|
156
137
|
# covers: entity[:field] => ...
|
157
138
|
when Flounder::Field
|
158
|
-
join_and_condition_part(
|
139
|
+
join_and_condition_part(field.arel_field, value)
|
159
140
|
# covers: :field_a.noteq => ...
|
160
141
|
when Flounder::SymbolExtensions::Modifier
|
161
142
|
join_and_condition_part(
|
162
|
-
entity,
|
163
143
|
field.to_arel_field(entity),
|
164
144
|
value,
|
165
145
|
field.kind)
|
@@ -167,7 +147,7 @@ module Flounder::Query
|
|
167
147
|
fail "Could not transform condition part. (#{field.inspect}, #{value.inspect})"
|
168
148
|
end
|
169
149
|
end
|
170
|
-
def join_and_condition_part
|
150
|
+
def join_and_condition_part arel_field, value, kind=:eq
|
171
151
|
case value
|
172
152
|
# covers subselects
|
173
153
|
when Flounder::Query::Base
|
@@ -31,6 +31,10 @@ module Flounder::Query
|
|
31
31
|
attr_reader :projection_prefixes
|
32
32
|
|
33
33
|
def _join join_node, entity
|
34
|
+
if entity.kind_of?(Symbol)
|
35
|
+
entity = domain[entity]
|
36
|
+
end
|
37
|
+
|
34
38
|
@last_join = entity
|
35
39
|
|
36
40
|
table = entity.table
|
@@ -66,7 +70,7 @@ module Flounder::Query
|
|
66
70
|
def on join_conditions
|
67
71
|
join_conditions.each do |k, v|
|
68
72
|
manager.on(
|
69
|
-
transform_tuple(
|
73
|
+
transform_tuple(k, join_field(v)))
|
70
74
|
end
|
71
75
|
self
|
72
76
|
end
|
data/lib/flounder.rb
CHANGED
@@ -31,11 +31,6 @@ module_function
|
|
31
31
|
def domain connection, &block
|
32
32
|
Domain.new(connection).tap { |d| yield d if block_given? }
|
33
33
|
end
|
34
|
-
|
35
|
-
def literal str
|
36
|
-
Arel::Nodes::SqlLiteral.new(str)
|
37
|
-
end
|
38
|
-
module_function :literal
|
39
34
|
end
|
40
35
|
|
41
36
|
Symbol.send(:include, Flounder::SymbolExtensions)
|
data/qed/index.md
CHANGED
@@ -63,13 +63,6 @@ Fields can be used fully qualified by going through the entity.
|
|
63
63
|
assert generates_sql("SELECT [fields] FROM \"users\" WHERE \"users\".\"user_id\" = \"users\".\"approver_id\"")
|
64
64
|
~~~
|
65
65
|
|
66
|
-
By default, symbols are interpreted as field names in the entity that you start your query with. But you can localize your `#where` clause to any other entity.
|
67
|
-
|
68
|
-
~~~ruby
|
69
|
-
users.where(posts, :id => 1).
|
70
|
-
assert generates_sql("SELECT [fields] FROM \"users\" WHERE \"posts\".\"id\" = 1")
|
71
|
-
~~~
|
72
|
-
|
73
66
|
# Some JOINs
|
74
67
|
|
75
68
|
Here are some non-crazy joins that also work.
|
@@ -82,6 +75,16 @@ Here are some non-crazy joins that also work.
|
|
82
75
|
assert generates_sql(%Q(SELECT [fields] FROM "users" LEFT OUTER JOIN "posts" ON "users"."id" = "posts"."user_id"))
|
83
76
|
~~~
|
84
77
|
|
78
|
+
Join also accepts symbols as argument - these will be turned into entities.
|
79
|
+
|
80
|
+
~~~ruby
|
81
|
+
domain[:users].join(:posts).on(:id => :user_id).
|
82
|
+
assert generates_sql(%Q(SELECT [fields] FROM "users" INNER JOIN "posts" ON "users"."id" = "posts"."user_id"))
|
83
|
+
|
84
|
+
domain[:users].outer_join(:posts).on(:id => :user_id).
|
85
|
+
assert generates_sql(%Q(SELECT [fields] FROM "users" LEFT OUTER JOIN "posts" ON "users"."id" = "posts"."user_id"))
|
86
|
+
~~~
|
87
|
+
|
85
88
|
Joining presents an interesting dilemma. There are two ways of joining things together, given three tables. The sequence A.B.C might mean to join A to B and C; it might also be interpreted to mean to join A to B and B to C. Here's how we solve this.
|
86
89
|
|
87
90
|
~~~ruby
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flounder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kaspar Schiess
|
@@ -88,11 +88,11 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- Gemfile
|
91
|
+
- Gemfile.lock
|
91
92
|
- HACKING
|
92
93
|
- HISTORY
|
93
94
|
- LICENSE
|
94
95
|
- README
|
95
|
-
- flounder-0.9.4.gem
|
96
96
|
- flounder.gemspec
|
97
97
|
- lib/flounder.rb
|
98
98
|
- lib/flounder/connection.rb
|
data/flounder-0.9.4.gem
DELETED
Binary file
|