activerecord-amazon-timestream-adapter 0.0.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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +3 -0
- data/lib/active_record/connection_adapters/amazon_timestream/database_statements.rb +37 -0
- data/lib/active_record/connection_adapters/amazon_timestream/quoting.rb +13 -0
- data/lib/active_record/connection_adapters/amazon_timestream/schema_statements.rb +32 -0
- data/lib/active_record/connection_adapters/amazon_timestream_adapter.rb +79 -0
- data/lib/activerecord-amazon-timestream-adapter.rb +3 -0
- data/lib/arel/visitors/amazon_timestream.rb +12 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 864faadd28644aa8d276fa335661e02ee37b55640cdd776c2e9f99eb2b58ff72
|
4
|
+
data.tar.gz: c38741466d3ea5c6a67acee2bf1ec4f5ac553eac0a840d9a4e66e8b14c8c4e86
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 72c9859c3dcc5a56f732822a85d15369a2652935e5542586ae6200ef9552ed1e29345fb25d90e6382a06f86114e1279e2228b0bf0d06bcf43e6ffadc7db849b8
|
7
|
+
data.tar.gz: 5ebb0ae723a08796cb58a6bc8c1f45792ae4824c8c03021eb7a80e9a36b51c8751897c0d7648ec7d2d9fb9504fe7dbae6773160643aa8a4ab9094261bb73d9d3
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2020 Francois Deschenes
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_record/result'
|
4
|
+
|
5
|
+
module ActiveRecord
|
6
|
+
module ConnectionAdapters
|
7
|
+
module AmazonTimestream
|
8
|
+
module DatabaseStatements
|
9
|
+
def execute(sql, name = nil)
|
10
|
+
log(sql, name) do
|
11
|
+
@query.query({ query_string: sql })
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def select_rows(sql, name = nil, binds = [])
|
16
|
+
exec_query(sql, name, binds).to_a.map(&:values)
|
17
|
+
end
|
18
|
+
|
19
|
+
def exec_query(sql, name = 'SQL', binds = [])
|
20
|
+
log(sql, name, binds) do
|
21
|
+
response = @query.query query_string: sql
|
22
|
+
|
23
|
+
ActiveRecord::Result.new response.column_info.map(&:name),
|
24
|
+
response.rows.map { |r| r.data.map(&:scalar_value) },
|
25
|
+
column_types_from(response.column_info)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def column_types_from(column_info)
|
32
|
+
column_info.each_with_object({}) { |c, h| h[c.name] = lookup_cast_type(c.type.scalar_type) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module ConnectionAdapters
|
5
|
+
module AmazonTimestream
|
6
|
+
module Quoting
|
7
|
+
def quote_table_name(table_name)
|
8
|
+
"\"#{@config[:database]}\".\"#{quote_string(table_name)}\""
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_record/connection_adapters/column'
|
4
|
+
|
5
|
+
module ActiveRecord
|
6
|
+
module ConnectionAdapters
|
7
|
+
module AmazonTimestream
|
8
|
+
module SchemaStatements
|
9
|
+
def tables(_name = nil)
|
10
|
+
response = @write.list_tables database_name: @config[:database]
|
11
|
+
|
12
|
+
response.tables.map(&:table_name)
|
13
|
+
end
|
14
|
+
|
15
|
+
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
|
20
|
+
end
|
21
|
+
|
22
|
+
def table_exists?(_table_name)
|
23
|
+
tables.include?(table_name)
|
24
|
+
end
|
25
|
+
|
26
|
+
def primary_key(_table_name)
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_record/connection_adapters/abstract_adapter'
|
4
|
+
require 'active_record/connection_adapters/amazon_timestream/database_statements'
|
5
|
+
require 'active_record/connection_adapters/amazon_timestream/quoting'
|
6
|
+
require 'active_record/connection_adapters/amazon_timestream/schema_statements'
|
7
|
+
require 'arel/visitors/amazon_timestream'
|
8
|
+
require 'aws-sdk-core'
|
9
|
+
require 'aws-sdk-timestreamquery'
|
10
|
+
require 'aws-sdk-timestreamwrite'
|
11
|
+
|
12
|
+
module ActiveRecord
|
13
|
+
class Base
|
14
|
+
def self.amazon_timestream_connection(config)
|
15
|
+
config = config.symbolize_keys
|
16
|
+
|
17
|
+
raise ArgumentError, 'No database specified. Missing argument: database.' unless config.key?(:database)
|
18
|
+
|
19
|
+
ConnectionAdapters::AmazonTimestreamAdapter.new(logger, config)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module ConnectionAdapters
|
24
|
+
class AmazonTimestreamAdapter < AbstractAdapter
|
25
|
+
ADAPTER_NAME = 'Amazon Timestream'
|
26
|
+
|
27
|
+
include AmazonTimestream::SchemaStatements
|
28
|
+
include AmazonTimestream::DatabaseStatements
|
29
|
+
include AmazonTimestream::Quoting
|
30
|
+
|
31
|
+
def initialize(logger, config)
|
32
|
+
super(nil, logger)
|
33
|
+
@config = config
|
34
|
+
@visitor = Arel::Visitors::AmazonTimestream.new self
|
35
|
+
connect!
|
36
|
+
end
|
37
|
+
|
38
|
+
def supports_explain?
|
39
|
+
false
|
40
|
+
end
|
41
|
+
|
42
|
+
def requires_reloading?
|
43
|
+
false
|
44
|
+
end
|
45
|
+
|
46
|
+
def active?
|
47
|
+
@query.query({ query_string: 'SELECT 1' })
|
48
|
+
true
|
49
|
+
rescue StandardError
|
50
|
+
false
|
51
|
+
end
|
52
|
+
|
53
|
+
protected
|
54
|
+
|
55
|
+
def initialize_type_map(mapping)
|
56
|
+
register_class_with_limit mapping, /boolean/i, Type::Boolean
|
57
|
+
register_class_with_limit mapping, /date/i, Type::Date
|
58
|
+
register_class_with_limit mapping, /double/i, Type::Float
|
59
|
+
register_class_with_limit mapping, /int/i, Type::Integer
|
60
|
+
register_class_with_limit mapping, /^time$/i, Type::Time
|
61
|
+
register_class_with_limit mapping, /timestamp/i, Type::DateTime
|
62
|
+
register_class_with_limit mapping, /varchar/i, Type::String
|
63
|
+
|
64
|
+
mapping.alias_type(/unknown/i, 'varchar')
|
65
|
+
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
|
+
end
|
78
|
+
end
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activerecord-amazon-timestream-adapter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Francois Deschenes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-11-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: arel
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '6.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '6.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: aws-sdk-core
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: aws-sdk-timestreamquery
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
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
|
+
description:
|
98
|
+
email: fdeschenes@me.com
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files: []
|
102
|
+
files:
|
103
|
+
- MIT-LICENSE
|
104
|
+
- README.md
|
105
|
+
- lib/active_record/connection_adapters/amazon_timestream/database_statements.rb
|
106
|
+
- lib/active_record/connection_adapters/amazon_timestream/quoting.rb
|
107
|
+
- lib/active_record/connection_adapters/amazon_timestream/schema_statements.rb
|
108
|
+
- lib/active_record/connection_adapters/amazon_timestream_adapter.rb
|
109
|
+
- lib/activerecord-amazon-timestream-adapter.rb
|
110
|
+
- lib/arel/visitors/amazon_timestream.rb
|
111
|
+
homepage: https://github.com/fdeschenes/activerecord-amazon-timestream-adapter
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
metadata: {}
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '2.4'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubygems_version: 3.0.3
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: ActiveRecord Amazon Timestream Adapter
|
134
|
+
test_files: []
|