clickhouse-activerecord 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/active_record/connection_adapters/clickhouse/oid/array.rb +30 -0
- data/lib/active_record/connection_adapters/clickhouse/schema_creation.rb +4 -1
- data/lib/active_record/connection_adapters/clickhouse/schema_statements.rb +5 -0
- data/lib/active_record/connection_adapters/clickhouse_adapter.rb +29 -1
- data/lib/clickhouse-activerecord/schema_dumper.rb +5 -0
- data/lib/clickhouse-activerecord/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92c0bdf3b6733bbe65fa0b4b096df7a171ca9625534965a82e675d2978141be6
|
4
|
+
data.tar.gz: f4a10214322bd7e1f36fd31d8c42821067d57ef8744727bcfd5ea975aa7b605c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29f6b4e129a393ad05d8d77386805d809cb6cbda37a6213122d5ad75edac3421dc51b70182a8f43cdac0b3d8b5a9208aa9aad3ba3d7161f108e5c1778e4c4cb0
|
7
|
+
data.tar.gz: 685b9c3b88819605ab596e41fe2a478e50b34d7c6d6eb53ce2ba603dd8324a6e4dc6a43498b063f98beac5a6301e3cb9be54283a15bd9f46bdf7fab94d2ba009
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module ConnectionAdapters
|
5
|
+
module Clickhouse
|
6
|
+
module OID # :nodoc:
|
7
|
+
class Array < Type::Value # :nodoc:
|
8
|
+
|
9
|
+
def initialize(sql_type)
|
10
|
+
@subtype = case sql_type
|
11
|
+
when /U?Int\d+/
|
12
|
+
:integer
|
13
|
+
when /DateTime/
|
14
|
+
:datetime
|
15
|
+
when /Date/
|
16
|
+
:date
|
17
|
+
else
|
18
|
+
:string
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def type
|
23
|
+
@subtype
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -22,6 +22,9 @@ module ActiveRecord
|
|
22
22
|
if options[:null] || options[:null].nil?
|
23
23
|
sql.gsub!(/\s+(.*)/, ' Nullable(\1)')
|
24
24
|
end
|
25
|
+
if options[:array]
|
26
|
+
sql.gsub!(/\s+(.*)/, ' Array(\1)')
|
27
|
+
end
|
25
28
|
sql.gsub!(/(\sString)\(\d+\)/, '\1')
|
26
29
|
sql << " DEFAULT #{quote_default_expression(options[:default], options[:column])}" if options_include_default?(options)
|
27
30
|
sql
|
@@ -33,7 +36,7 @@ module ActiveRecord
|
|
33
36
|
# rails 6.1
|
34
37
|
opts ||= options.options
|
35
38
|
end
|
36
|
-
|
39
|
+
|
37
40
|
if opts.present?
|
38
41
|
create_sql << " ENGINE = #{opts}"
|
39
42
|
else
|
@@ -23,6 +23,11 @@ module ActiveRecord
|
|
23
23
|
raise ActiveRecord::ActiveRecordError, "Response: #{e.message}"
|
24
24
|
end
|
25
25
|
|
26
|
+
def exec_insert_all(sql, name)
|
27
|
+
do_execute(sql, name, format: nil)
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
26
31
|
def exec_update(_sql, _name = nil, _binds = [])
|
27
32
|
raise ActiveRecord::ActiveRecordError, 'Clickhouse update is not supported'
|
28
33
|
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'clickhouse-activerecord/arel/visitors/to_sql'
|
4
4
|
require 'clickhouse-activerecord/arel/table'
|
5
5
|
require 'clickhouse-activerecord/migration'
|
6
|
+
require 'active_record/connection_adapters/clickhouse/oid/array'
|
6
7
|
require 'active_record/connection_adapters/clickhouse/oid/date'
|
7
8
|
require 'active_record/connection_adapters/clickhouse/oid/date_time'
|
8
9
|
require 'active_record/connection_adapters/clickhouse/oid/big_integer'
|
@@ -17,6 +18,7 @@ module ActiveRecord
|
|
17
18
|
# Establishes a connection to the database that's used by all Active Record objects
|
18
19
|
def clickhouse_connection(config)
|
19
20
|
config = config.symbolize_keys
|
21
|
+
|
20
22
|
if config[:connection]
|
21
23
|
connection = {
|
22
24
|
connection: config[:connection]
|
@@ -27,6 +29,9 @@ module ActiveRecord
|
|
27
29
|
host: config[:host] || 'localhost',
|
28
30
|
port: port,
|
29
31
|
ssl: config[:ssl].present? ? config[:ssl] : port == 443,
|
32
|
+
sslca: config[:sslca],
|
33
|
+
read_timeout: config[:read_timeout],
|
34
|
+
write_timeout: config[:write_timeout],
|
30
35
|
}
|
31
36
|
end
|
32
37
|
|
@@ -190,12 +195,16 @@ module ActiveRecord
|
|
190
195
|
register_class_with_limit m, %r(Int128), Type::Integer
|
191
196
|
register_class_with_limit m, %r(Int256), Type::Integer
|
192
197
|
|
193
|
-
register_class_with_limit m, %r(
|
198
|
+
register_class_with_limit m, %r(UInt8), Type::UnsignedInteger
|
194
199
|
register_class_with_limit m, %r(UInt16), Type::UnsignedInteger
|
195
200
|
register_class_with_limit m, %r(UInt32), Type::UnsignedInteger
|
196
201
|
register_class_with_limit m, %r(UInt64), Type::UnsignedInteger
|
197
202
|
#register_class_with_limit m, %r(UInt128), Type::UnsignedInteger #not implemnted in clickhouse
|
198
203
|
register_class_with_limit m, %r(UInt256), Type::UnsignedInteger
|
204
|
+
# register_class_with_limit m, %r(Array), Clickhouse::OID::Array
|
205
|
+
m.register_type(%r(Array)) do |sql_type|
|
206
|
+
Clickhouse::OID::Array.new(sql_type)
|
207
|
+
end
|
199
208
|
end
|
200
209
|
|
201
210
|
# Quoting time without microseconds
|
@@ -323,6 +332,19 @@ module ActiveRecord
|
|
323
332
|
cluster ? "#{sql} ON CLUSTER #{cluster}" : sql
|
324
333
|
end
|
325
334
|
|
335
|
+
def supports_insert_on_duplicate_skip?
|
336
|
+
true
|
337
|
+
end
|
338
|
+
|
339
|
+
def supports_insert_on_duplicate_update?
|
340
|
+
true
|
341
|
+
end
|
342
|
+
|
343
|
+
def build_insert_sql(insert) # :nodoc:
|
344
|
+
sql = +"INSERT #{insert.into} #{insert.values_list}"
|
345
|
+
sql
|
346
|
+
end
|
347
|
+
|
326
348
|
protected
|
327
349
|
|
328
350
|
def last_inserted_id(result)
|
@@ -339,6 +361,12 @@ module ActiveRecord
|
|
339
361
|
|
340
362
|
def connect
|
341
363
|
@connection = @connection_parameters[:connection] || Net::HTTP.start(@connection_parameters[:host], @connection_parameters[:port], use_ssl: @connection_parameters[:ssl], verify_mode: OpenSSL::SSL::VERIFY_NONE)
|
364
|
+
|
365
|
+
@connection.ca_file = @connection_parameters[:ca_file] if @connection_parameters[:ca_file]
|
366
|
+
@connection.read_timeout = @connection_parameters[:read_timeout] if @connection_parameters[:read_timeout]
|
367
|
+
@connection.write_timeout = @connection_parameters[:write_timeout] if @connection_parameters[:write_timeout]
|
368
|
+
|
369
|
+
@connection
|
342
370
|
end
|
343
371
|
|
344
372
|
def apply_replica(table, options)
|
@@ -144,9 +144,14 @@ HEADER
|
|
144
144
|
(column.sql_type =~ /(Nullable)?\(?UInt\d+\)?/).nil? ? false : nil
|
145
145
|
end
|
146
146
|
|
147
|
+
def schema_array(column)
|
148
|
+
(column.sql_type =~ /Array?\(/).nil? ? nil : true
|
149
|
+
end
|
150
|
+
|
147
151
|
def prepare_column_options(column)
|
148
152
|
spec = {}
|
149
153
|
spec[:unsigned] = schema_unsigned(column)
|
154
|
+
spec[:array] = schema_array(column)
|
150
155
|
spec.merge(super).compact
|
151
156
|
end
|
152
157
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clickhouse-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Odintsov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -112,6 +112,7 @@ files:
|
|
112
112
|
- bin/console
|
113
113
|
- bin/setup
|
114
114
|
- clickhouse-activerecord.gemspec
|
115
|
+
- lib/active_record/connection_adapters/clickhouse/oid/array.rb
|
115
116
|
- lib/active_record/connection_adapters/clickhouse/oid/big_integer.rb
|
116
117
|
- lib/active_record/connection_adapters/clickhouse/oid/date.rb
|
117
118
|
- lib/active_record/connection_adapters/clickhouse/oid/date_time.rb
|