brick 1.0.70 → 1.0.71
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/brick/extensions.rb +59 -24
- data/lib/brick/frameworks/rails/engine.rb +1 -1
- data/lib/brick/version_number.rb +1 -1
- data/lib/brick.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: e50dce8dd2821ec196836393569138d4e18c53a9ef1e3e910ddffa6bc3788824
|
4
|
+
data.tar.gz: 982b26f7ed3a14f69589b6c422b37a5ec42b210c095cf85ef0eeab151ea80c59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c0e76b3e092d35f57045f3dd106ae9b8c90b266df0a7c0c973824ed20c1ac41560f124420d164e4e9d170b9a386345f424f19bce01bf041c9ebb553c842e553
|
7
|
+
data.tar.gz: 6d257bbec4c364456be5167b55c2eb377d94cdd0485e56dfb699daf14f3dce7a46c94c91534ecbe9c8f090b564e8752de0c3b88cf7560e01ca9d8388a3ec9930
|
data/lib/brick/extensions.rb
CHANGED
@@ -99,13 +99,14 @@ module ActiveRecord
|
|
99
99
|
dsl
|
100
100
|
end
|
101
101
|
|
102
|
-
def self.brick_parse_dsl(build_array = nil, prefix = [], translations = {}, is_polymorphic = false)
|
102
|
+
def self.brick_parse_dsl(build_array = nil, prefix = [], translations = {}, emit_dsl = false, is_polymorphic = false)
|
103
103
|
build_array = ::Brick::JoinArray.new.tap { |ary| ary.replace([build_array]) } if build_array.is_a?(::Brick::JoinHash)
|
104
104
|
build_array = ::Brick::JoinArray.new unless build_array.nil? || build_array.is_a?(Array)
|
105
105
|
members = []
|
106
106
|
bracket_name = nil
|
107
107
|
prefix = [prefix] unless prefix.is_a?(Array)
|
108
108
|
if (dsl = ::Brick.config.model_descrips[name] || brick_get_dsl)
|
109
|
+
dsl2 = +''
|
109
110
|
klass = nil
|
110
111
|
dsl.each_char do |ch|
|
111
112
|
if bracket_name
|
@@ -125,7 +126,15 @@ module ActiveRecord
|
|
125
126
|
end
|
126
127
|
translations[parts[0..-2].join('.')] = klass
|
127
128
|
end
|
128
|
-
|
129
|
+
if klass.column_names.exclude?(parts.last) &&
|
130
|
+
(klass = (orig_class = klass).reflect_on_association(possible_dsl = parts.pop.to_sym)&.klass)
|
131
|
+
members2, dsl2a = klass.brick_parse_dsl(build_array, prefix + [possible_dsl], translations, true)
|
132
|
+
members += members2
|
133
|
+
dsl2 << dsl2a
|
134
|
+
else
|
135
|
+
dsl2 << "[#{bracket_name}]"
|
136
|
+
members << parts
|
137
|
+
end
|
129
138
|
bracket_name = nil
|
130
139
|
else
|
131
140
|
bracket_name << ch
|
@@ -133,13 +142,20 @@ module ActiveRecord
|
|
133
142
|
elsif ch == '['
|
134
143
|
bracket_name = +''
|
135
144
|
klass = self
|
145
|
+
else
|
146
|
+
dsl2 << ch
|
136
147
|
end
|
137
148
|
end
|
149
|
+
# Rewrite the DSL just in case it's different because we had to expand it
|
150
|
+
unless emit_dsl
|
151
|
+
# puts "Compare:\n #{dsl}\n #{dsl2}"
|
152
|
+
::Brick.config.model_descrips[name] = dsl2
|
153
|
+
end
|
138
154
|
else # With no DSL available, still put this prefix into the JoinArray so we can get primary key (ID) info from this table
|
139
155
|
x = prefix.each_with_object(build_array) { |v, s| s[v.to_sym] }
|
140
156
|
x[prefix.last] = nil unless prefix.empty? # Using []= will "hydrate" any missing part(s) in our whole series
|
141
157
|
end
|
142
|
-
members
|
158
|
+
emit_dsl ? [members, dsl2] : members
|
143
159
|
end
|
144
160
|
|
145
161
|
# If available, parse simple DSL attached to a model in order to provide a friendlier name.
|
@@ -169,9 +185,12 @@ module ActiveRecord
|
|
169
185
|
this_obj = caches.fetch(obj_name) { caches[obj_name] = this_obj&.send(part.to_sym) }
|
170
186
|
break if this_obj.nil?
|
171
187
|
end
|
188
|
+
if this_obj.is_a?(ActiveRecord::Base) && (obj_descrip = this_obj.class.brick_descrip(this_obj))
|
189
|
+
this_obj = obj_descrip
|
190
|
+
end
|
172
191
|
this_obj&.to_s || ''
|
173
192
|
end
|
174
|
-
is_brackets_have_content = true unless
|
193
|
+
is_brackets_have_content = true unless datum.blank?
|
175
194
|
output << (datum || '')
|
176
195
|
bracket_name = nil
|
177
196
|
else
|
@@ -244,7 +263,8 @@ module ActiveRecord
|
|
244
263
|
|
245
264
|
# join_array will receive this relation name when calling #brick_parse_dsl
|
246
265
|
_br_bt_descrip[bt.first] = if bt[1].is_a?(Array)
|
247
|
-
|
266
|
+
# Last two params here: "false" is for don't emit DSL, and "true" is for yes, we are polymorphic
|
267
|
+
bt[1].each_with_object({}) { |bt_class, s| s[bt_class] = bt_class.brick_parse_dsl(join_array, bt.first, translations, false, true) }
|
248
268
|
else
|
249
269
|
{ bt.last => bt[1].brick_parse_dsl(join_array, bt.first, translations) }
|
250
270
|
end
|
@@ -409,15 +429,37 @@ module ActiveRecord
|
|
409
429
|
if selects&.empty? # Default to all columns
|
410
430
|
tbl_no_schema = table.name.split('.').last
|
411
431
|
columns.each do |col|
|
412
|
-
|
432
|
+
if (col_name = col.name) == 'class'
|
433
|
+
col_alias = " AS #{col.name}_"
|
434
|
+
else
|
435
|
+
alias_name = nil
|
436
|
+
idx = 0
|
437
|
+
col_name.each_char do |c|
|
438
|
+
unless (c >= 'a' && c <= 'z') ||
|
439
|
+
c == '_' ||
|
440
|
+
(c >= 'A' && c <= 'Z') ||
|
441
|
+
(c >= '0' && c <= '9')
|
442
|
+
(alias_name ||= col_name.dup)[idx] = 'x'
|
443
|
+
end
|
444
|
+
++idx
|
445
|
+
end
|
446
|
+
col_alias = " AS #{alias_name}" if alias_name
|
447
|
+
end
|
413
448
|
selects << if is_mysql
|
414
449
|
"`#{tbl_no_schema}`.`#{col_name}`#{col_alias}"
|
415
450
|
elsif is_postgres || is_mssql
|
416
451
|
# Postgres can not use DISTINCT with any columns that are XML, so for any of those just convert to text
|
417
|
-
cast_as_text = '::text' if is_distinct && Brick.relations[klass.table_name]&.[](:cols)&.[](
|
452
|
+
cast_as_text = '::text' if is_distinct && Brick.relations[klass.table_name]&.[](:cols)&.[](col_name)&.first&.start_with?('xml')
|
418
453
|
"\"#{tbl_no_schema}\".\"#{col_name}\"#{cast_as_text}#{col_alias}"
|
419
|
-
|
420
|
-
|
454
|
+
elsif col.type # Could be Sqlite or Oracle
|
455
|
+
if col_alias
|
456
|
+
"#{tbl_no_schema}.#{col_name}#{col_alias}"
|
457
|
+
else
|
458
|
+
"#{tbl_no_schema}.#{col_name}"
|
459
|
+
end
|
460
|
+
else # Oracle with a custom data type
|
461
|
+
typ = col.sql_type
|
462
|
+
"'<#{typ.end_with?('_TYP') ? typ[0..-5] : typ}>' AS #{col.name}"
|
421
463
|
end
|
422
464
|
end
|
423
465
|
end
|
@@ -1415,7 +1457,7 @@ module ActiveRecord::ConnectionHandling
|
|
1415
1457
|
# ActiveRecord::Base.connection.current_database will be something like "XEPDB1"
|
1416
1458
|
::Brick.default_schema = schema = ActiveRecord::Base.connection.raw_connection.username
|
1417
1459
|
::Brick.db_schemas = {}
|
1418
|
-
|
1460
|
+
ActiveRecord::Base.execute_sql("SELECT username FROM sys.all_users WHERE ORACLE_MAINTAINED != 'Y'").each { |s| ::Brick.db_schemas[s.first] = nil }
|
1419
1461
|
when 'SQLite'
|
1420
1462
|
sql = "SELECT m.name AS relation_name, UPPER(m.type) AS table_type,
|
1421
1463
|
p.name AS column_name, p.type AS data_type,
|
@@ -1478,8 +1520,9 @@ module ActiveRecord::ConnectionHandling
|
|
1478
1520
|
schema_and_tables = case ActiveRecord::Base.connection.adapter_name
|
1479
1521
|
when 'OracleEnhanced'
|
1480
1522
|
sql =
|
1481
|
-
"SELECT c.owner AS schema, c.table_name AS relation_name,
|
1482
|
-
|
1523
|
+
"SELECT c.owner AS schema, c.table_name AS relation_name,
|
1524
|
+
CASE WHEN v.owner IS NULL THEN 'BASE_TABLE' ELSE 'VIEW' END AS table_type,
|
1525
|
+
c.column_name, c.data_type,
|
1483
1526
|
COALESCE(c.data_length, c.data_precision) AS max_length,
|
1484
1527
|
CASE ac.constraint_type WHEN 'P' THEN 'PRIMARY KEY' END AS const,
|
1485
1528
|
ac.constraint_name AS \"key\",
|
@@ -1487,9 +1530,11 @@ module ActiveRecord::ConnectionHandling
|
|
1487
1530
|
FROM all_tab_cols c
|
1488
1531
|
LEFT OUTER JOIN all_cons_columns acc ON acc.owner = c.owner AND acc.table_name = c.table_name AND acc.column_name = c.column_name
|
1489
1532
|
LEFT OUTER JOIN all_constraints ac ON ac.owner = acc.owner AND ac.table_name = acc.table_name AND ac.constraint_name = acc.constraint_name AND constraint_type = 'P'
|
1533
|
+
LEFT OUTER JOIN all_views v ON c.owner = v.owner AND c.table_name = v.view_name
|
1490
1534
|
WHERE c.owner IN (#{::Brick.db_schemas.keys.map { |s| "'#{s}'" }.join(', ')})
|
1535
|
+
AND c.table_name NOT IN (?, ?)
|
1491
1536
|
ORDER BY 1, 2, c.internal_column_id, acc.position"
|
1492
|
-
|
1537
|
+
ActiveRecord::Base.execute_sql(sql, *ar_tables)
|
1493
1538
|
else
|
1494
1539
|
ActiveRecord::Base.retrieve_schema_and_tables(sql)
|
1495
1540
|
end
|
@@ -1579,7 +1624,7 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
|
|
1579
1624
|
WHERE ac.constraint_type = 'R'
|
1580
1625
|
AND ac.owner IN (#{schemas})
|
1581
1626
|
AND ac.r_owner IN (#{schemas})"
|
1582
|
-
fk_references = ActiveRecord::Base.
|
1627
|
+
fk_references = ActiveRecord::Base.execute_sql(sql)
|
1583
1628
|
end
|
1584
1629
|
::Brick.is_oracle = true if ActiveRecord::Base.connection.adapter_name == 'OracleEnhanced'
|
1585
1630
|
# ::Brick.default_schema ||= schema ||= 'public' if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
|
@@ -1679,16 +1724,6 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
|
|
1679
1724
|
ar_imtn = ActiveRecord.version >= ::Gem::Version.new('5.0') ? ActiveRecord::Base.internal_metadata_table_name : ''
|
1680
1725
|
[ar_smtn, ar_imtn]
|
1681
1726
|
end
|
1682
|
-
|
1683
|
-
def execute_oracle(*sql_args)
|
1684
|
-
cursor = ActiveRecord::Base.execute_sql(*sql_args)
|
1685
|
-
result = []
|
1686
|
-
while row = cursor.fetch()
|
1687
|
-
result << row
|
1688
|
-
end
|
1689
|
-
cursor.close
|
1690
|
-
result
|
1691
|
-
end
|
1692
1727
|
end
|
1693
1728
|
|
1694
1729
|
# ==========================================
|
@@ -1090,9 +1090,9 @@ flatpickr(\".timepicker\", {enableTime: true, noCalendar: true});
|
|
1090
1090
|
mermaid.initialize({
|
1091
1091
|
startOnLoad: true,
|
1092
1092
|
securityLevel: \"loose\",
|
1093
|
+
er: { useMaxWidth: false },
|
1093
1094
|
mermaid: {callback: function(objId) {
|
1094
1095
|
var svg = document.getElementById(objId);
|
1095
|
-
svg.removeAttribute(\"width\");
|
1096
1096
|
var cb;
|
1097
1097
|
for(cb in cbs) {
|
1098
1098
|
var gErd = svg.getElementById(cb);
|
data/lib/brick/version_number.rb
CHANGED
data/lib/brick.rb
CHANGED
@@ -560,7 +560,7 @@ ActiveSupport.on_load(:active_record) do
|
|
560
560
|
class << self
|
561
561
|
def execute_sql(sql, *param_array)
|
562
562
|
param_array = param_array.first if param_array.length == 1 && param_array.first.is_a?(Array)
|
563
|
-
if ActiveRecord::Base.connection.adapter_name
|
563
|
+
if ['OracleEnhanced', 'SQLServer'].include?(ActiveRecord::Base.connection.adapter_name)
|
564
564
|
connection.exec_query(send(:sanitize_sql_array, [sql] + param_array)).rows
|
565
565
|
else
|
566
566
|
connection.execute(send(:sanitize_sql_array, [sql] + param_array))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.71
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lorin Thwaits
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|