activerecord-amazon-timestream-adapter 0.0.1 → 0.0.2

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: 864faadd28644aa8d276fa335661e02ee37b55640cdd776c2e9f99eb2b58ff72
4
- data.tar.gz: c38741466d3ea5c6a67acee2bf1ec4f5ac553eac0a840d9a4e66e8b14c8c4e86
3
+ metadata.gz: 40439344b1bf48a7fa48d5870fe9dc26d8d1b3d6cf26de59e74356142caec035
4
+ data.tar.gz: 99fd64958f63efc61c9fd473639059b1c3394e7509fb3616d6caa84d14a192bc
5
5
  SHA512:
6
- metadata.gz: 72c9859c3dcc5a56f732822a85d15369a2652935e5542586ae6200ef9552ed1e29345fb25d90e6382a06f86114e1279e2228b0bf0d06bcf43e6ffadc7db849b8
7
- data.tar.gz: 5ebb0ae723a08796cb58a6bc8c1f45792ae4824c8c03021eb7a80e9a36b51c8751897c0d7648ec7d2d9fb9504fe7dbae6773160643aa8a4ab9094261bb73d9d3
6
+ metadata.gz: 7bb934253342e57663de04d9fb2237852893676c218b48446fc052609676202c6ec6e6baa4e161fe24845989f036927ba4641292adb0e79da91466cb6abb8c27
7
+ data.tar.gz: 6d118754cdccdd5721c92f656819adde144a2a69f7068ec62ef1c253cbc7b21594d112d186ab9efa6b38b9f94bdb26796e86478e7c491558221c2cf713f1f291
@@ -8,7 +8,7 @@ module ActiveRecord
8
8
  module DatabaseStatements
9
9
  def execute(sql, name = nil)
10
10
  log(sql, name) do
11
- @query.query({ query_string: sql })
11
+ @connection.query({ query_string: sql })
12
12
  end
13
13
  end
14
14
 
@@ -18,7 +18,7 @@ module ActiveRecord
18
18
 
19
19
  def exec_query(sql, name = 'SQL', binds = [])
20
20
  log(sql, name, binds) do
21
- response = @query.query query_string: sql
21
+ response = @connection.query query_string: sql
22
22
 
23
23
  ActiveRecord::Result.new response.column_info.map(&:name),
24
24
  response.rows.map { |r| r.data.map(&:scalar_value) },
@@ -5,7 +5,7 @@ module ActiveRecord
5
5
  module AmazonTimestream
6
6
  module Quoting
7
7
  def quote_table_name(table_name)
8
- "\"#{@config[:database]}\".\"#{quote_string(table_name)}\""
8
+ "\"#{@database}\".\"#{quote_string(table_name)}\""
9
9
  end
10
10
  end
11
11
  end
@@ -7,16 +7,13 @@ module ActiveRecord
7
7
  module AmazonTimestream
8
8
  module SchemaStatements
9
9
  def tables(_name = nil)
10
- response = @write.list_tables database_name: @config[:database]
11
-
12
- response.tables.map(&:table_name)
10
+ response = @connection.query({ query_string: "SHOW TABLES FROM \"#{@database}\"" })
11
+ response.rows.map { |r| r.data[0].scalar_value }
13
12
  end
14
13
 
15
14
  def columns(table_name, _name = nil)
16
- response = @query.query query_string: "SELECT * FROM #{quote_table_name(table_name)} LIMIT 1"
17
- response.column_info.map do |column|
18
- Column.new(column.name, nil, lookup_cast_type(column.type.scalar_type))
19
- end
15
+ response = @connection.query({ query_string: "DESCRIBE \"#{@database}\".\"#{table_name}\"" })
16
+ response.rows.map { |r| Column.new(r.data[0].scalar_value, nil, lookup_cast_type(r.data[1].scalar_value)) }
20
17
  end
21
18
 
22
19
  def table_exists?(_table_name)
@@ -7,7 +7,6 @@ require 'active_record/connection_adapters/amazon_timestream/schema_statements'
7
7
  require 'arel/visitors/amazon_timestream'
8
8
  require 'aws-sdk-core'
9
9
  require 'aws-sdk-timestreamquery'
10
- require 'aws-sdk-timestreamwrite'
11
10
 
12
11
  module ActiveRecord
13
12
  class Base
@@ -16,7 +15,10 @@ module ActiveRecord
16
15
 
17
16
  raise ArgumentError, 'No database specified. Missing argument: database.' unless config.key?(:database)
18
17
 
19
- ConnectionAdapters::AmazonTimestreamAdapter.new(logger, config)
18
+ credentials = Aws::Credentials.new config[:username], config[:password] if config[:username] && config[:password]
19
+ connection = Aws::TimestreamQuery::Client.new credentials: credentials
20
+
21
+ ConnectionAdapters::AmazonTimestreamAdapter.new(connection, logger, config[:database])
20
22
  end
21
23
  end
22
24
 
@@ -28,11 +30,10 @@ module ActiveRecord
28
30
  include AmazonTimestream::DatabaseStatements
29
31
  include AmazonTimestream::Quoting
30
32
 
31
- def initialize(logger, config)
32
- super(nil, logger)
33
- @config = config
33
+ def initialize(connection, logger, database)
34
+ super(connection, logger)
35
+ @database = database
34
36
  @visitor = Arel::Visitors::AmazonTimestream.new self
35
- connect!
36
37
  end
37
38
 
38
39
  def supports_explain?
@@ -44,10 +45,7 @@ module ActiveRecord
44
45
  end
45
46
 
46
47
  def active?
47
- @query.query({ query_string: 'SELECT 1' })
48
48
  true
49
- rescue StandardError
50
- false
51
49
  end
52
50
 
53
51
  protected
@@ -63,17 +61,6 @@ module ActiveRecord
63
61
 
64
62
  mapping.alias_type(/unknown/i, 'varchar')
65
63
  end
66
-
67
- private
68
-
69
- def connect!
70
- if @config[:username] && @config[:password]
71
- credentials = Aws::Credentials.new(@config[:username], @config[:password])
72
- end
73
-
74
- @query = Aws::TimestreamQuery::Client.new credentials: credentials
75
- @write = Aws::TimestreamWrite::Client.new credentials: credentials
76
- end
77
64
  end
78
65
  end
79
66
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-amazon-timestream-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francois Deschenes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-12 00:00:00.000000000 Z
11
+ date: 2020-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.0'
83
- - !ruby/object:Gem::Dependency
84
- name: aws-sdk-timestreamwrite
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '1.0'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '1.0'
97
83
  description:
98
84
  email: fdeschenes@me.com
99
85
  executables: []