motor-admin 0.2.11 → 0.2.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/motor/queries/run_query.rb +37 -3
- data/lib/motor/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d0e456f8e9d1dc83186c2ef270182308da0bb43bab8779eaa391b2f6f3c7a4f
|
4
|
+
data.tar.gz: 1f5a52343c0ba8ca6b4c622b221656a9e38ac2df6678a6659653e2469f71c92d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b58213d454339da735ef28bb926eea83b910a9399a38892a34744c85ba64f7cce0c9668d40c10afe839807ea194a2144282e20fc6b0133f2bb215ec3f5a5b0f5
|
7
|
+
data.tar.gz: e945c189f9929b3afd5eada7330f8b83cc62386a3ac1718d1956bc4cd6b499933defdf0e0c094221170c4b0d58584cf64024e3ac7084d8ed3dcf3c59b5a21449
|
@@ -83,18 +83,52 @@ module Motor
|
|
83
83
|
# @param result [ActiveRecord::Result]
|
84
84
|
# @return [Hash]
|
85
85
|
def build_columns_hash(result)
|
86
|
-
result.columns.map do |column_name|
|
87
|
-
|
86
|
+
result.columns.map.with_index do |column_name, index|
|
87
|
+
column_type_class = result.column_types[column_name]
|
88
|
+
|
89
|
+
column_type =
|
90
|
+
if column_type_class
|
91
|
+
ActiveRecordUtils::Types.find_name_for_type(column_type_class)
|
92
|
+
else
|
93
|
+
not_nil_value = result.rows.reduce(nil) do |acc, row|
|
94
|
+
column = row[index]
|
95
|
+
|
96
|
+
break column unless column.nil?
|
97
|
+
|
98
|
+
acc
|
99
|
+
end
|
100
|
+
|
101
|
+
fetch_column_type_from_value(not_nil_value)
|
102
|
+
end
|
88
103
|
|
89
104
|
{
|
90
105
|
name: column_name,
|
91
106
|
display_name: column_name.humanize,
|
92
|
-
column_type:
|
107
|
+
column_type: column_type,
|
93
108
|
is_array: column_type.class.to_s == 'ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array'
|
94
109
|
}
|
95
110
|
end
|
96
111
|
end
|
97
112
|
|
113
|
+
# @param value [Object]
|
114
|
+
# @return [String]
|
115
|
+
def fetch_column_type_from_value(value)
|
116
|
+
case value
|
117
|
+
when Integer
|
118
|
+
'integer'
|
119
|
+
when Float
|
120
|
+
'float'
|
121
|
+
when Time
|
122
|
+
'datetime'
|
123
|
+
when Date
|
124
|
+
'date'
|
125
|
+
when TrueClass, FalseClass
|
126
|
+
'boolean'
|
127
|
+
else
|
128
|
+
'string'
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
98
132
|
# @param query [Motor::Query]
|
99
133
|
# @param limit [Integer]
|
100
134
|
# @param variables_hash [Hash]
|
data/lib/motor/version.rb
CHANGED