smql 0.0.4.7 → 0.0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/smql_to_ar/query_builder.rb +35 -11
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.4.
|
1
|
+
0.0.4.8
|
@@ -32,13 +32,36 @@ class SmqlToAR
|
|
32
32
|
end
|
33
33
|
|
34
34
|
class Aliases < Hash
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
35
|
+
attr_accessor :counter, :prefix
|
36
|
+
|
37
|
+
def initialize prefix, *a, &e
|
38
|
+
@counter, @prefix = 0, prefix || 'smql'
|
40
39
|
super *a, &e
|
41
40
|
end
|
41
|
+
|
42
|
+
def format name
|
43
|
+
pre, suf = name.split( ',', 2)
|
44
|
+
return name unless suf
|
45
|
+
pre += ",#{@counter += 1},"
|
46
|
+
l = 60-pre.length
|
47
|
+
n = suf[(suf.length<=l ? 0 : -l)..-1]
|
48
|
+
n == suf ? pre+n : "#{pre},,,#{n}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def name n
|
52
|
+
n.collect( &:to_alias).join ','
|
53
|
+
end
|
54
|
+
|
55
|
+
def [] k
|
56
|
+
n = name k
|
57
|
+
v = super n
|
58
|
+
v = self[k] = format( "#{prefix},#{n}") unless v
|
59
|
+
v
|
60
|
+
end
|
61
|
+
|
62
|
+
def []= k, v
|
63
|
+
super name( k), v
|
64
|
+
end
|
42
65
|
end
|
43
66
|
|
44
67
|
attr_reader :table_alias, :model, :table_model, :base_table, :_where, :_select, :_wobs, :_joins, :prefix, :_vid
|
@@ -48,7 +71,7 @@ class SmqlToAR
|
|
48
71
|
@prefix = "smql"
|
49
72
|
@logger = SmqlToAR.logger
|
50
73
|
@table_alias = Aliases.new @prefix
|
51
|
-
@_vid, @_where, @_wobs, @model, @
|
74
|
+
@_vid, @_where, @_wobs, @model, @quote = 0, SmqlToAR::And[], {}, model, model.connection
|
52
75
|
@base_table = [Column::Col.new( model.table_name)]
|
53
76
|
@table_alias[ @base_table] = @base_table.first
|
54
77
|
t = quote_table_name @base_table.first.col
|
@@ -77,7 +100,7 @@ class SmqlToAR
|
|
77
100
|
end
|
78
101
|
|
79
102
|
def quote_column_name name
|
80
|
-
@
|
103
|
+
@quote.quote_column_name( name).gsub /"\."/, ','
|
81
104
|
end
|
82
105
|
|
83
106
|
def quote_table_name name
|
@@ -85,7 +108,7 @@ class SmqlToAR
|
|
85
108
|
when Array, Column::Col then @table_alias[Array.wrap name]
|
86
109
|
else name.to_s
|
87
110
|
end
|
88
|
-
@
|
111
|
+
@quote.quote_table_name name
|
89
112
|
end
|
90
113
|
|
91
114
|
def column table, name
|
@@ -93,7 +116,7 @@ class SmqlToAR
|
|
93
116
|
end
|
94
117
|
|
95
118
|
def build_join orig, pretable, table, prekey, key
|
96
|
-
"
|
119
|
+
"\tLEFT JOIN #{orig} AS #{quote_table_name table}\n\tON #{column pretable, prekey} = #{column table, key}\n"
|
97
120
|
end
|
98
121
|
|
99
122
|
def sub_joins table, col, model, query
|
@@ -104,7 +127,8 @@ class SmqlToAR
|
|
104
127
|
def join_ table, model, query, pretable = nil
|
105
128
|
pretable ||= table[0...-1]
|
106
129
|
@table_model[ table] = model
|
107
|
-
|
130
|
+
@table_model.rehash
|
131
|
+
premodel = @table_model.find {|k,v| pretable == k }[1]
|
108
132
|
t = @table_alias[ table]
|
109
133
|
pt = quote_table_name table[ 0...-1]
|
110
134
|
refl = premodel.reflections[table.last.to_sym]
|
@@ -195,7 +219,7 @@ class SmqlToAR
|
|
195
219
|
|
196
220
|
class SubBuilder < Array
|
197
221
|
attr_reader :parent, :_where
|
198
|
-
delegate :wobs, :joins, :includes, :sub_joins, :vid, :quote_column_name, :
|
222
|
+
delegate :wobs, :joins, :includes, :sub_joins, :vid, :quote_column_name, :quote, :quote_table_name, :column, :to => :parent
|
199
223
|
|
200
224
|
def initialize parent, tmp = false
|
201
225
|
@parent = parent
|
metadata
CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
|
|
6
6
|
- 0
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.0.4.
|
9
|
+
- 8
|
10
|
+
version: 0.0.4.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Denis Knauf
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-01-12 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|