clickhouse-activerecord 0.4.11 → 0.4.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8d1d60f75e0f889dc5d947df77924f1490c0325f097d634048fb25405eeca70
4
- data.tar.gz: 309eda1c3f605682c04525fce8633b85a73a38643e367f33d87588939f7815fe
3
+ metadata.gz: ad0ad1c7545498f275ff975d35ee9dde7d2f644516932ee33ab65796360426a0
4
+ data.tar.gz: 15b32b155c596c8cdd9e187681a128a4806ca7e2c457e0f833ffc66ba9c994af
5
5
  SHA512:
6
- metadata.gz: 5727f1a23c48e04db1052bfbf4c56af412338be88f4b985ed6700e9a833436bcde893ba9cb1ed7b89473dae95b31e4b70de26c6885cce10b8fffcdb9c65fbb3d
7
- data.tar.gz: 18fad92b704c1c41b97029facbc020111c3b067cbb825d6e5c4d11d6a4b7a220873b922aea7112ec741f1d87a1a5c2217a11047e764959a2edffb98e0b7f2463
6
+ metadata.gz: 8f80ffc1c70dbbdd489ea59627e85a72f538276c80adc0fe5ee4319c222a61da2acd1680ea42bd8c4c4b713fb354f7498a3469cc3cfd17f9003c8dbd607719b2
7
+ data.tar.gz: 9c91108f18bb9b133708a682ee3dfec238cc54afac480fcada95e876bb051843a7269e3d81c6298299b1bbffbc5a8a47975add7919144d220845fd87c710122b
data/README.md CHANGED
@@ -35,6 +35,21 @@ default: &default
35
35
  replica_name: '{replica}' # replica macros name, optional for creating replicated tables
36
36
  ```
37
37
 
38
+ Alternatively if you wish to pass a custom `Net::HTTP` transport (or any other
39
+ object which supports a `.post()` function with the same parameters as
40
+ `Net::HTTP`'s), you can do this directly instead of specifying
41
+ `host`/`port`/`ssl`:
42
+
43
+ ```ruby
44
+ class ActionView < ActiveRecord::Base
45
+ establish_connection(
46
+ adapter: 'clickhouse',
47
+ database: 'database',
48
+ connection: Net::HTTP.start('http://example.org', 8123)
49
+ )
50
+ end
51
+ ```
52
+
38
53
  ## Usage in Rails 5
39
54
 
40
55
  Add your `database.yml` connection information with postfix `_clickhouse` for you environment:
@@ -17,8 +17,10 @@ module ActiveRecord
17
17
  def exec_query(sql, name = nil, binds = [], prepare: false)
18
18
  result = do_execute(sql, name)
19
19
  ActiveRecord::Result.new(result['meta'].map { |m| m['name'] }, result['data'])
20
- rescue StandardError => _e
21
- raise ActiveRecord::ActiveRecordError, "Response: #{result}"
20
+ rescue ActiveRecord::ActiveRecordError => e
21
+ raise e
22
+ rescue StandardError => e
23
+ raise ActiveRecord::ActiveRecordError, "Response: #{e.message}"
22
24
  end
23
25
 
24
26
  def exec_update(_sql, _name = nil, _binds = [])
@@ -17,9 +17,18 @@ module ActiveRecord
17
17
  # Establishes a connection to the database that's used by all Active Record objects
18
18
  def clickhouse_connection(config)
19
19
  config = config.symbolize_keys
20
- host = config[:host] || 'localhost'
21
- port = config[:port] || 8123
22
- ssl = config[:ssl].present? ? config[:ssl] : port == 443
20
+ if config[:connection]
21
+ connection = {
22
+ connection: config[:connection]
23
+ }
24
+ else
25
+ port = config[:port] || 8123
26
+ connection = {
27
+ host: config[:host] || 'localhost',
28
+ port: port,
29
+ ssl: config[:ssl].present? ? config[:ssl] : port == 443,
30
+ }
31
+ end
23
32
 
24
33
  if config.key?(:database)
25
34
  database = config[:database]
@@ -27,7 +36,7 @@ module ActiveRecord
27
36
  raise ArgumentError, 'No database specified. Missing argument: database.'
28
37
  end
29
38
 
30
- ConnectionAdapters::ClickhouseAdapter.new(logger, [host, port, ssl], { user: config[:username], password: config[:password], database: database }.compact, config)
39
+ ConnectionAdapters::ClickhouseAdapter.new(logger, connection, { user: config[:username], password: config[:password], database: database }.compact, config)
31
40
  end
32
41
  end
33
42
  end
@@ -325,7 +334,7 @@ module ActiveRecord
325
334
  private
326
335
 
327
336
  def connect
328
- @connection = Net::HTTP.start(@connection_parameters[0], @connection_parameters[1], use_ssl: @connection_parameters[2], verify_mode: OpenSSL::SSL::VERIFY_NONE)
337
+ @connection = @connection_parameters[:connection] || Net::HTTP.start(@connection_parameters[:host], @connection_parameters[:port], use_ssl: @connection_parameters[:ssl], verify_mode: OpenSSL::SSL::VERIFY_NONE)
329
338
  end
330
339
 
331
340
  def apply_replica(table, options)
@@ -1,3 +1,3 @@
1
1
  module ClickhouseActiverecord
2
- VERSION = '0.4.11'
2
+ VERSION = '0.4.12'
3
3
  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.4.11
4
+ version: 0.4.12
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-03-23 00:00:00.000000000 Z
11
+ date: 2021-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler