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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44191e2a6c44d59b2965f540cfc406ddf8ac1086cdea394631a9bded9f7d31a7
4
- data.tar.gz: ab2dbc754e795d947fe3ed7a38276b91f591c9bb8d5c2349b62ca47022cfc9c2
3
+ metadata.gz: ec6ef6942310f94d0893f99b34c0d131bed54e0b0d3bee033b10998e09f5b1ef
4
+ data.tar.gz: a8fe62d1d072c78c96d9e171f17f8e8f039bd12714c443d7b3921e40d696ef6c
5
5
  SHA512:
6
- metadata.gz: fbf38052a71a818d4746973e302b17190074e7d2b570dced929efd6e792c6ee92d39d021ef262db9d4ac616fed25e54a0798974cbe305756d23cd3e6be03838d
7
- data.tar.gz: 87831c2a9c650ee5ad86eb9753a3f3f26fbfa775c52879504ddb36c5b0a869e213a367cbda3572c241061a1af5722786ba7e861ee25de2f64dac4c1681c7ad89
6
+ metadata.gz: 973a0716b0602f10175eec3eff15cd3515b36f58fd2021d65eb1e6a307808534b58f4fc514bac8d742fd82115ba757b99401a6f50314a899331019f2bc3d961f
7
+ data.tar.gz: b0f7fb3dba7d8d3810b45b2b0342cacd100ba857969c423f88d28e6c076d1d11879b7a72ced07434ecd88088be93a2dfecb7572cda1a9f396aff4813018c8971
@@ -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
 
@@ -13,24 +13,24 @@ module Bmg
13
13
  end
14
14
 
15
15
  def delete
16
- dataset.delete
16
+ base_table.delete
17
17
  end
18
18
 
19
19
  def insert(arg)
20
20
  case arg
21
21
  when Hash then
22
- dataset.insert(arg.merge(type.predicate.constants))
22
+ base_table.insert(arg.merge(type.predicate.constants))
23
23
  when Enumerable then
24
- dataset.multi_insert(arg.map { |x|
24
+ base_table.multi_insert(arg.map { |x|
25
25
  x.merge(type.predicate.constants)
26
26
  })
27
27
  else
28
- dataset.insert(arg.merge(type.predicate.constants))
28
+ base_table.insert(arg.merge(type.predicate.constants))
29
29
  end
30
30
  end
31
31
 
32
32
  def update(arg)
33
- dataset.update(arg)
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
- ::Sequel.as(::Sequel.expr(sexpr.table_name.to_sym), ::Sequel.identifier(sexpr.as_name))
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)
@@ -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
- when String, Symbol then table_name(table)
102
- else table
103
- end
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) ]
@@ -2,7 +2,7 @@ module Bmg
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 16
5
- TINY = 3
5
+ TINY = 4
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end
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.3
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-09 00:00:00.000000000 Z
11
+ date: 2019-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: predicate