bmg 0.16.3 → 0.16.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bmg/sequel.rb +1 -1
- data/lib/bmg/sequel/relation.rb +11 -5
- data/lib/bmg/sequel/translator.rb +7 -1
- data/lib/bmg/sql/builder.rb +5 -3
- data/lib/bmg/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec6ef6942310f94d0893f99b34c0d131bed54e0b0d3bee033b10998e09f5b1ef
|
4
|
+
data.tar.gz: a8fe62d1d072c78c96d9e171f17f8e8f039bd12714c443d7b3921e40d696ef6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 973a0716b0602f10175eec3eff15cd3515b36f58fd2021d65eb1e6a307808534b58f4fc514bac8d742fd82115ba757b99401a6f50314a899331019f2bc3d961f
|
7
|
+
data.tar.gz: b0f7fb3dba7d8d3810b45b2b0342cacd100ba857969c423f88d28e6c076d1d11879b7a72ced07434ecd88088be93a2dfecb7572cda1a9f396aff4813018c8971
|
data/lib/bmg/sequel.rb
CHANGED
@@ -28,7 +28,7 @@ module Bmg
|
|
28
28
|
module_function :sequel_params
|
29
29
|
|
30
30
|
def infer_type(sequel_db, source)
|
31
|
-
TypeInference.new(sequel_db).call(source) if source.is_a?(Symbol)
|
31
|
+
TypeInference.new(sequel_db).call(source) if source.is_a?(Symbol) || source.is_a?(::Sequel::SQL::QualifiedIdentifier)
|
32
32
|
end
|
33
33
|
module_function :infer_type
|
34
34
|
|
data/lib/bmg/sequel/relation.rb
CHANGED
@@ -13,24 +13,24 @@ module Bmg
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def delete
|
16
|
-
|
16
|
+
base_table.delete
|
17
17
|
end
|
18
18
|
|
19
19
|
def insert(arg)
|
20
20
|
case arg
|
21
21
|
when Hash then
|
22
|
-
|
22
|
+
base_table.insert(arg.merge(type.predicate.constants))
|
23
23
|
when Enumerable then
|
24
|
-
|
24
|
+
base_table.multi_insert(arg.map { |x|
|
25
25
|
x.merge(type.predicate.constants)
|
26
26
|
})
|
27
27
|
else
|
28
|
-
|
28
|
+
base_table.insert(arg.merge(type.predicate.constants))
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
def update(arg)
|
33
|
-
|
33
|
+
base_table.update(arg)
|
34
34
|
end
|
35
35
|
|
36
36
|
def to_ast
|
@@ -52,6 +52,12 @@ module Bmg
|
|
52
52
|
@dataset ||= Translator.new(sequel_db).call(self.expr)
|
53
53
|
end
|
54
54
|
|
55
|
+
def base_table
|
56
|
+
raise InvalidUpdateError unless self.expr.respond_to?(:table_spec)
|
57
|
+
raise InvalidUpdateError unless self.expr.table_spec.first == :table_as
|
58
|
+
sequel_db[self.expr.table_spec.table_name.to_sym]
|
59
|
+
end
|
60
|
+
|
55
61
|
def _instance(type, builder, expr)
|
56
62
|
Relation.new(type, builder, expr, sequel_db)
|
57
63
|
end
|
@@ -119,7 +119,13 @@ module Bmg
|
|
119
119
|
end
|
120
120
|
|
121
121
|
def on_table_as(sexpr)
|
122
|
-
|
122
|
+
table_name = case sexpr.table_name
|
123
|
+
when String, Symbol then ::Sequel.expr(sexpr.table_name.to_sym)
|
124
|
+
when ::Sequel::SQL::QualifiedIdentifier then sexpr.table_name
|
125
|
+
else
|
126
|
+
raise ArgumentError, "Invalid table name `#{sexpr.table_name}`"
|
127
|
+
end
|
128
|
+
::Sequel.as(table_name, ::Sequel.identifier(sexpr.as_name))
|
123
129
|
end
|
124
130
|
|
125
131
|
def on_subquery_as(sexpr)
|
data/lib/bmg/sql/builder.rb
CHANGED
@@ -89,6 +89,7 @@ module Bmg
|
|
89
89
|
def from_clause(table, qualifier)
|
90
90
|
arg = case table
|
91
91
|
when String, Symbol then table_as(table, qualifier)
|
92
|
+
when ::Sequel::SQL::QualifiedIdentifier then table_as(table, qualifier)
|
92
93
|
when Expr then subquery_as(table, qualifier)
|
93
94
|
else native_table_as(table, qualifier)
|
94
95
|
end
|
@@ -98,9 +99,10 @@ module Bmg
|
|
98
99
|
|
99
100
|
def table_as(table, qualifier)
|
100
101
|
table = case table
|
101
|
-
|
102
|
-
|
103
|
-
|
102
|
+
when String, Symbol then table_name(table)
|
103
|
+
when ::Sequel::SQL::QualifiedIdentifier then table_name(table)
|
104
|
+
else table
|
105
|
+
end
|
104
106
|
[:table_as,
|
105
107
|
table,
|
106
108
|
range_var_name(qualifier) ]
|
data/lib/bmg/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bmg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.16.
|
4
|
+
version: 0.16.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Lambeau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: predicate
|