ovirt_metrics 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_record/connection_adapters/ovirt_postgresql_adapter.rb +30 -0
- data/lib/ovirt_metrics.rb +4 -1
- data/lib/ovirt_metrics/version.rb +1 -1
- metadata +3 -35
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/column.rb +0 -15
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/database_statements.rb +0 -170
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/explain_pretty_printer.rb +0 -42
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid.rb +0 -31
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/array.rb +0 -70
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/bit.rb +0 -52
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/bit_varying.rb +0 -13
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/bytea.rb +0 -15
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/cidr.rb +0 -48
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/date_time.rb +0 -21
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/decimal.rb +0 -13
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/enum.rb +0 -19
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/hstore.rb +0 -59
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/inet.rb +0 -13
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/json.rb +0 -10
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/jsonb.rb +0 -23
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/money.rb +0 -39
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/point.rb +0 -43
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/rails_5_1_point.rb +0 -50
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/range.rb +0 -93
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/specialized_string.rb +0 -15
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/type_map_initializer.rb +0 -109
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/uuid.rb +0 -21
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/vector.rb +0 -26
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/xml.rb +0 -28
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/quoting.rb +0 -116
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/referential_integrity.rb +0 -49
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/schema_definitions.rb +0 -180
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/schema_dumper.rb +0 -47
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/schema_statements.rb +0 -682
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/type_metadata.rb +0 -35
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/utils.rb +0 -77
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql_adapter.rb +0 -856
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1af74e7888e42f106793d65f064e8ef47f4660a704f8a04d89c231c7ed652c1a
|
4
|
+
data.tar.gz: 7cbfc1fbf819d4c4164aea5f9207f69a26ed9e6ad2a1fc1258925f70751f7a7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c95385d550ae26e15bdeef7b02d419afbd8ce0443aced77aa863921977271fa7acb2f7edd9ddea9a093b62809e15e8d7a30deb0470a2eea2daeca6fd021db822
|
7
|
+
data.tar.gz: a1a8eccd66bfe8754e326c6ce9888259b4adfb359a2f919f3eb9427f227a53e6a32d28d32454d61d7988986e47389872a56d7490d12dc6deeaefae62876e2385
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionHandling # :nodoc:
|
3
|
+
def ovirt_postgresql_connection(config)
|
4
|
+
conn_params = config.symbolize_keys
|
5
|
+
|
6
|
+
conn_params.delete_if { |_, v| v.nil? }
|
7
|
+
|
8
|
+
conn_params[:user] = conn_params.delete(:username) if conn_params[:username]
|
9
|
+
conn_params[:dbname] = conn_params.delete(:database) if conn_params[:database]
|
10
|
+
|
11
|
+
valid_conn_param_keys = PG::Connection.conndefaults_hash.keys + [:requiressl]
|
12
|
+
conn_params.slice!(*valid_conn_param_keys)
|
13
|
+
|
14
|
+
ConnectionAdapters::OvirtPostgreSQLAdapter.new(nil, logger, conn_params, config)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module ConnectionAdapters
|
19
|
+
class OvirtPostgreSQLAdapter < PostgreSQLAdapter
|
20
|
+
ADAPTER_NAME = "OvirtPostgreSQL"
|
21
|
+
|
22
|
+
def check_version
|
23
|
+
msg = "The version of PostgreSQL (#{postgresql_version}) is too old (9.2+ required)"
|
24
|
+
if postgresql_version < 90200
|
25
|
+
raise msg
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/ovirt_metrics.rb
CHANGED
@@ -27,7 +27,10 @@ module OvirtMetrics
|
|
27
27
|
opts ||= {}
|
28
28
|
opts[:port] ||= 5432
|
29
29
|
opts[:database] ||= DEFAULT_HISTORY_DATABASE_NAME
|
30
|
-
opts[:adapter]
|
30
|
+
opts[:adapter] = begin
|
31
|
+
require "active_record/connection_adapters/ovirt_postgresql_adapter"
|
32
|
+
'ovirt_postgresql'
|
33
|
+
end
|
31
34
|
|
32
35
|
# Don't allow accidental connections to localhost. A blank host will
|
33
36
|
# connect to localhost, so don't allow that at all.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ovirt_metrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleg Barenboim
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-08-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -135,39 +135,7 @@ files:
|
|
135
135
|
- ".rspec"
|
136
136
|
- LICENSE.txt
|
137
137
|
- README.md
|
138
|
-
- lib/active_record/connection_adapters/
|
139
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/database_statements.rb
|
140
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/explain_pretty_printer.rb
|
141
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid.rb
|
142
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/array.rb
|
143
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/bit.rb
|
144
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/bit_varying.rb
|
145
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/bytea.rb
|
146
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/cidr.rb
|
147
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/date_time.rb
|
148
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/decimal.rb
|
149
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/enum.rb
|
150
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/hstore.rb
|
151
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/inet.rb
|
152
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/json.rb
|
153
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/jsonb.rb
|
154
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/money.rb
|
155
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/point.rb
|
156
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/rails_5_1_point.rb
|
157
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/range.rb
|
158
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/specialized_string.rb
|
159
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/type_map_initializer.rb
|
160
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/uuid.rb
|
161
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/vector.rb
|
162
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/xml.rb
|
163
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/quoting.rb
|
164
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/referential_integrity.rb
|
165
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/schema_definitions.rb
|
166
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/schema_dumper.rb
|
167
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/schema_statements.rb
|
168
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/type_metadata.rb
|
169
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql/utils.rb
|
170
|
-
- lib/active_record/connection_adapters/ovirt_legacy_postgresql_adapter.rb
|
138
|
+
- lib/active_record/connection_adapters/ovirt_postgresql_adapter.rb
|
171
139
|
- lib/ovirt_metrics.rb
|
172
140
|
- lib/ovirt_metrics/column_definitions.rb
|
173
141
|
- lib/ovirt_metrics/configurator.rb
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module ConnectionAdapters
|
3
|
-
# PostgreSQL-specific extensions to column definitions in a table.
|
4
|
-
class OvirtLegacyPostgreSQLColumn < Column #:nodoc:
|
5
|
-
delegate :array, :oid, :fmod, to: :sql_type_metadata
|
6
|
-
alias :array? :array
|
7
|
-
|
8
|
-
def serial?
|
9
|
-
return unless default_function
|
10
|
-
|
11
|
-
%r{\Anextval\('"?#{table_name}_#{name}_seq"?'::regclass\)\z} === default_function
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,170 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module ConnectionAdapters
|
3
|
-
module OvirtLegacyPostgreSQL
|
4
|
-
module DatabaseStatements
|
5
|
-
def explain(arel, binds = [])
|
6
|
-
sql = "EXPLAIN #{to_sql(arel, binds)}"
|
7
|
-
OvirtLegacyPostgreSQL::ExplainPrettyPrinter.new.pp(exec_query(sql, 'EXPLAIN', binds))
|
8
|
-
end
|
9
|
-
|
10
|
-
def select_value(arel, name = nil, binds = [])
|
11
|
-
arel, binds = binds_from_relation arel, binds
|
12
|
-
sql = to_sql(arel, binds)
|
13
|
-
execute_and_clear(sql, name, binds) do |result|
|
14
|
-
result.getvalue(0, 0) if result.ntuples > 0 && result.nfields > 0
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def select_values(arel, name = nil, binds = [])
|
19
|
-
arel, binds = binds_from_relation arel, binds
|
20
|
-
sql = to_sql(arel, binds)
|
21
|
-
execute_and_clear(sql, name, binds) do |result|
|
22
|
-
if result.nfields > 0
|
23
|
-
result.column_values(0)
|
24
|
-
else
|
25
|
-
[]
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# Executes a SELECT query and returns an array of rows. Each row is an
|
31
|
-
# array of field values.
|
32
|
-
def select_rows(sql, name = nil, binds = [])
|
33
|
-
execute_and_clear(sql, name, binds) do |result|
|
34
|
-
result.values
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# The internal PostgreSQL identifier of the money data type.
|
39
|
-
MONEY_COLUMN_TYPE_OID = 790 #:nodoc:
|
40
|
-
# The internal PostgreSQL identifier of the BYTEA data type.
|
41
|
-
BYTEA_COLUMN_TYPE_OID = 17 #:nodoc:
|
42
|
-
|
43
|
-
# create a 2D array representing the result set
|
44
|
-
def result_as_array(res) #:nodoc:
|
45
|
-
# check if we have any binary column and if they need escaping
|
46
|
-
ftypes = Array.new(res.nfields) do |i|
|
47
|
-
[i, res.ftype(i)]
|
48
|
-
end
|
49
|
-
|
50
|
-
rows = res.values
|
51
|
-
return rows unless ftypes.any? { |_, x|
|
52
|
-
x == BYTEA_COLUMN_TYPE_OID || x == MONEY_COLUMN_TYPE_OID
|
53
|
-
}
|
54
|
-
|
55
|
-
typehash = ftypes.group_by { |_, type| type }
|
56
|
-
binaries = typehash[BYTEA_COLUMN_TYPE_OID] || []
|
57
|
-
monies = typehash[MONEY_COLUMN_TYPE_OID] || []
|
58
|
-
|
59
|
-
rows.each do |row|
|
60
|
-
# unescape string passed BYTEA field (OID == 17)
|
61
|
-
binaries.each do |index, _|
|
62
|
-
row[index] = unescape_bytea(row[index])
|
63
|
-
end
|
64
|
-
|
65
|
-
# If this is a money type column and there are any currency symbols,
|
66
|
-
# then strip them off. Indeed it would be prettier to do this in
|
67
|
-
# OvirtLegacyPostgreSQLColumn.string_to_decimal but would break form input
|
68
|
-
# fields that call value_before_type_cast.
|
69
|
-
monies.each do |index, _|
|
70
|
-
data = row[index]
|
71
|
-
# Because money output is formatted according to the locale, there are two
|
72
|
-
# cases to consider (note the decimal separators):
|
73
|
-
# (1) $12,345,678.12
|
74
|
-
# (2) $12.345.678,12
|
75
|
-
case data
|
76
|
-
when /^-?\D+[\d,]+\.\d{2}$/ # (1)
|
77
|
-
data.gsub!(/[^-\d.]/, '')
|
78
|
-
when /^-?\D+[\d.]+,\d{2}$/ # (2)
|
79
|
-
data.gsub!(/[^-\d,]/, '').sub!(/,/, '.')
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# Queries the database and returns the results in an Array-like object
|
86
|
-
def query(sql, name = nil) #:nodoc:
|
87
|
-
log(sql, name) do
|
88
|
-
result_as_array @connection.async_exec(sql)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
# Executes an SQL statement, returning a PGresult object on success
|
93
|
-
# or raising a PGError exception otherwise.
|
94
|
-
# Note: the PGresult object is manually memory managed; if you don't
|
95
|
-
# need it specifically, you many want consider the exec_query wrapper.
|
96
|
-
def execute(sql, name = nil)
|
97
|
-
log(sql, name) do
|
98
|
-
@connection.async_exec(sql)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def exec_query(sql, name = 'SQL', binds = [], prepare: false)
|
103
|
-
execute_and_clear(sql, name, binds, prepare: prepare) do |result|
|
104
|
-
types = {}
|
105
|
-
fields = result.fields
|
106
|
-
fields.each_with_index do |fname, i|
|
107
|
-
ftype = result.ftype i
|
108
|
-
fmod = result.fmod i
|
109
|
-
types[fname] = get_oid_type(ftype, fmod, fname)
|
110
|
-
end
|
111
|
-
ActiveRecord::Result.new(fields, result.values, types)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
def exec_delete(sql, name = 'SQL', binds = [])
|
116
|
-
execute_and_clear(sql, name, binds) {|result| result.cmd_tuples }
|
117
|
-
end
|
118
|
-
alias :exec_update :exec_delete
|
119
|
-
|
120
|
-
def sql_for_insert(sql, pk, id_value, sequence_name, binds) # :nodoc:
|
121
|
-
if pk.nil?
|
122
|
-
# Extract the table from the insert sql. Yuck.
|
123
|
-
table_ref = extract_table_ref_from_insert_sql(sql)
|
124
|
-
pk = primary_key(table_ref) if table_ref
|
125
|
-
end
|
126
|
-
|
127
|
-
if pk && use_insert_returning?
|
128
|
-
sql = "#{sql} RETURNING #{quote_column_name(pk)}"
|
129
|
-
end
|
130
|
-
|
131
|
-
super
|
132
|
-
end
|
133
|
-
|
134
|
-
def exec_insert(sql, name, binds, pk = nil, sequence_name = nil)
|
135
|
-
val = exec_query(sql, name, binds)
|
136
|
-
if !use_insert_returning? && pk
|
137
|
-
unless sequence_name
|
138
|
-
table_ref = extract_table_ref_from_insert_sql(sql)
|
139
|
-
sequence_name = default_sequence_name(table_ref, pk)
|
140
|
-
return val unless sequence_name
|
141
|
-
end
|
142
|
-
last_insert_id_result(sequence_name)
|
143
|
-
else
|
144
|
-
val
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
# Begins a transaction.
|
149
|
-
def begin_db_transaction
|
150
|
-
execute "BEGIN"
|
151
|
-
end
|
152
|
-
|
153
|
-
def begin_isolated_db_transaction(isolation)
|
154
|
-
begin_db_transaction
|
155
|
-
execute "SET TRANSACTION ISOLATION LEVEL #{transaction_isolation_levels.fetch(isolation)}"
|
156
|
-
end
|
157
|
-
|
158
|
-
# Commits a transaction.
|
159
|
-
def commit_db_transaction
|
160
|
-
execute "COMMIT"
|
161
|
-
end
|
162
|
-
|
163
|
-
# Aborts a transaction.
|
164
|
-
def exec_rollback_db_transaction
|
165
|
-
execute "ROLLBACK"
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/explain_pretty_printer.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module ConnectionAdapters
|
3
|
-
module OvirtLegacyPostgreSQL
|
4
|
-
class ExplainPrettyPrinter # :nodoc:
|
5
|
-
# Pretty prints the result of an EXPLAIN in a way that resembles the output of the
|
6
|
-
# PostgreSQL shell:
|
7
|
-
#
|
8
|
-
# QUERY PLAN
|
9
|
-
# ------------------------------------------------------------------------------
|
10
|
-
# Nested Loop Left Join (cost=0.00..37.24 rows=8 width=0)
|
11
|
-
# Join Filter: (posts.user_id = users.id)
|
12
|
-
# -> Index Scan using users_pkey on users (cost=0.00..8.27 rows=1 width=4)
|
13
|
-
# Index Cond: (id = 1)
|
14
|
-
# -> Seq Scan on posts (cost=0.00..28.88 rows=8 width=4)
|
15
|
-
# Filter: (posts.user_id = 1)
|
16
|
-
# (6 rows)
|
17
|
-
#
|
18
|
-
def pp(result)
|
19
|
-
header = result.columns.first
|
20
|
-
lines = result.rows.map(&:first)
|
21
|
-
|
22
|
-
# We add 2 because there's one char of padding at both sides, note
|
23
|
-
# the extra hyphens in the example above.
|
24
|
-
width = [header, *lines].map(&:length).max + 2
|
25
|
-
|
26
|
-
pp = []
|
27
|
-
|
28
|
-
pp << header.center(width).rstrip
|
29
|
-
pp << '-' * width
|
30
|
-
|
31
|
-
pp += lines.map {|line| " #{line}"}
|
32
|
-
|
33
|
-
nrows = result.rows.length
|
34
|
-
rows_label = nrows == 1 ? 'row' : 'rows'
|
35
|
-
pp << "(#{nrows} #{rows_label})"
|
36
|
-
|
37
|
-
pp.join("\n") + "\n"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/array'
|
2
|
-
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/bit'
|
3
|
-
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/bit_varying'
|
4
|
-
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/bytea'
|
5
|
-
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/cidr'
|
6
|
-
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/date_time'
|
7
|
-
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/decimal'
|
8
|
-
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/enum'
|
9
|
-
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/hstore'
|
10
|
-
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/inet'
|
11
|
-
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/json'
|
12
|
-
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/jsonb'
|
13
|
-
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/money'
|
14
|
-
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/point'
|
15
|
-
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/rails_5_1_point'
|
16
|
-
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/range'
|
17
|
-
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/specialized_string'
|
18
|
-
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/uuid'
|
19
|
-
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/vector'
|
20
|
-
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/xml'
|
21
|
-
|
22
|
-
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/type_map_initializer'
|
23
|
-
|
24
|
-
module ActiveRecord
|
25
|
-
module ConnectionAdapters
|
26
|
-
module OvirtLegacyPostgreSQL
|
27
|
-
module OID # :nodoc:
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module ConnectionAdapters
|
3
|
-
module OvirtLegacyPostgreSQL
|
4
|
-
module OID # :nodoc:
|
5
|
-
class Array < Type::Value # :nodoc:
|
6
|
-
include Type::Helpers::Mutable
|
7
|
-
|
8
|
-
attr_reader :subtype, :delimiter
|
9
|
-
delegate :type, :user_input_in_time_zone, :limit, to: :subtype
|
10
|
-
|
11
|
-
def initialize(subtype, delimiter = ',')
|
12
|
-
@subtype = subtype
|
13
|
-
@delimiter = delimiter
|
14
|
-
|
15
|
-
@pg_encoder = PG::TextEncoder::Array.new name: "#{type}[]", delimiter: delimiter
|
16
|
-
@pg_decoder = PG::TextDecoder::Array.new name: "#{type}[]", delimiter: delimiter
|
17
|
-
end
|
18
|
-
|
19
|
-
def deserialize(value)
|
20
|
-
if value.is_a?(::String)
|
21
|
-
type_cast_array(@pg_decoder.decode(value), :deserialize)
|
22
|
-
else
|
23
|
-
super
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def cast(value)
|
28
|
-
if value.is_a?(::String)
|
29
|
-
value = @pg_decoder.decode(value)
|
30
|
-
end
|
31
|
-
type_cast_array(value, :cast)
|
32
|
-
end
|
33
|
-
|
34
|
-
def serialize(value)
|
35
|
-
if value.is_a?(::Array)
|
36
|
-
@pg_encoder.encode(type_cast_array(value, :serialize))
|
37
|
-
else
|
38
|
-
super
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def ==(other)
|
43
|
-
other.is_a?(Array) &&
|
44
|
-
subtype == other.subtype &&
|
45
|
-
delimiter == other.delimiter
|
46
|
-
end
|
47
|
-
|
48
|
-
def type_cast_for_schema(value)
|
49
|
-
return super unless value.is_a?(::Array)
|
50
|
-
"[" + value.map { |v| subtype.type_cast_for_schema(v) }.join(", ") + "]"
|
51
|
-
end
|
52
|
-
|
53
|
-
def map(value, &block)
|
54
|
-
value.map(&block)
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
|
59
|
-
def type_cast_array(value, method)
|
60
|
-
if value.is_a?(::Array)
|
61
|
-
value.map { |item| type_cast_array(item, method) }
|
62
|
-
else
|
63
|
-
@subtype.public_send(method, value)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|