activerecord-singlestore 1.0.0
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
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d77662b66894082d8d02b16f90f7304fe01aea347b796c87d420bb5de4049969
|
|
4
|
+
data.tar.gz: 4b980242a1192d23e195bd12a7a15a1e96038ddcdf1effc08e711bbbaff3bc4b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 4ce79be52692e3cb61100be4657de0deda3608f69e271265e6ba54bd8bc14954b68cba53d393c79057a38b75a4a53725885e5c87e7f9885ddb9c63e1a9f40c0b
|
|
7
|
+
data.tar.gz: 55cdd57d80a32191a8d7a0a0d4b7f6a4567b02a6a2dbd031a389c304ba12d785de90ff85ea5abb3527752397663fc9aa99fd5862f9ffdf70c76313d2c9b05532
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module ActiveRecord
|
|
2
|
+
module ConnectionAdapters
|
|
3
|
+
module Singlestore
|
|
4
|
+
class TableDefinition < ActiveRecord::ConnectionAdapters::TableDefinition
|
|
5
|
+
attr_reader :rowstore
|
|
6
|
+
|
|
7
|
+
def initialize(
|
|
8
|
+
conn,
|
|
9
|
+
name,
|
|
10
|
+
temporary: false,
|
|
11
|
+
if_not_exists: false,
|
|
12
|
+
options: nil,
|
|
13
|
+
rowstore: nil,
|
|
14
|
+
as: nil,
|
|
15
|
+
comment: nil,
|
|
16
|
+
**
|
|
17
|
+
)
|
|
18
|
+
@conn = conn
|
|
19
|
+
@columns_hash = {}
|
|
20
|
+
@indexes = []
|
|
21
|
+
@foreign_keys = []
|
|
22
|
+
@primary_keys = nil
|
|
23
|
+
@check_constraints = []
|
|
24
|
+
@temporary = temporary
|
|
25
|
+
@if_not_exists = if_not_exists
|
|
26
|
+
@options = options
|
|
27
|
+
@rowstore = rowstore
|
|
28
|
+
@as = as
|
|
29
|
+
@name = name
|
|
30
|
+
@comment = comment
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_record/connection_adapters/abstract_mysql_adapter"
|
|
4
|
+
require "active_record/connection_adapters/mysql2_adapter"
|
|
5
|
+
require "active_record/connection_adapters/mysql/database_statements"
|
|
6
|
+
require "active_record/connection_adapters/singlestore/schema_creation"
|
|
7
|
+
require "active_record/connection_adapters/singlestore/table_definition"
|
|
8
|
+
|
|
9
|
+
gem "mysql2", ">= 0.4.4"
|
|
10
|
+
|
|
11
|
+
module ActiveRecord
|
|
12
|
+
module ConnectionHandling # :nodoc:
|
|
13
|
+
ER_BAD_DB_ERROR = 1049
|
|
14
|
+
|
|
15
|
+
# Establishes a connection to the database that's used by all Active Record objects.
|
|
16
|
+
def singlestore_connection(config)
|
|
17
|
+
config = config.symbolize_keys
|
|
18
|
+
|
|
19
|
+
config[:username] = "root" if config[:username].nil?
|
|
20
|
+
config[:flags] ||= 0
|
|
21
|
+
config[:variables] = {sql_mode: ''} if config[:variables].nil?
|
|
22
|
+
|
|
23
|
+
if config[:flags].kind_of? Array
|
|
24
|
+
config[:flags].push "FOUND_ROWS"
|
|
25
|
+
else
|
|
26
|
+
config[:flags] |= Mysql2::Client::FOUND_ROWS
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
client = Mysql2::Client.new(config)
|
|
30
|
+
ConnectionAdapters::SinglestoreAdapter.new(client, logger, nil, config)
|
|
31
|
+
rescue Mysql2::Error => error
|
|
32
|
+
if error.error_number == ER_BAD_DB_ERROR
|
|
33
|
+
raise ActiveRecord::NoDatabaseError
|
|
34
|
+
else
|
|
35
|
+
raise
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
module ConnectionAdapters
|
|
41
|
+
class SinglestoreAdapter < AbstractMysqlAdapter
|
|
42
|
+
ADAPTER_NAME = "SingleStore"
|
|
43
|
+
|
|
44
|
+
include MySQL::DatabaseStatements
|
|
45
|
+
|
|
46
|
+
def initialize(connection, logger, connection_options, config)
|
|
47
|
+
superclass_config = config.reverse_merge(prepared_statements: false)
|
|
48
|
+
super(connection, logger, connection_options, superclass_config)
|
|
49
|
+
configure_connection
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def self.database_exists?(config)
|
|
53
|
+
!!ActiveRecord::Base.singlestore_connection(config)
|
|
54
|
+
rescue ActiveRecord::NoDatabaseError
|
|
55
|
+
false
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def supports_json?
|
|
59
|
+
!mariadb? && database_version >= "5.7.8"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def supports_comments?
|
|
63
|
+
true
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def supports_comments_in_create?
|
|
67
|
+
true
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def supports_savepoints?
|
|
71
|
+
true
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def supports_lazy_transactions?
|
|
75
|
+
true
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def supports_advisory_locks?
|
|
79
|
+
false
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# HELPER METHODS ===========================================
|
|
83
|
+
|
|
84
|
+
def each_hash(result) # :nodoc:
|
|
85
|
+
if block_given?
|
|
86
|
+
result.each(as: :hash, symbolize_keys: true) do |row|
|
|
87
|
+
yield row
|
|
88
|
+
end
|
|
89
|
+
else
|
|
90
|
+
to_enum(:each_hash, result)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def error_number(exception)
|
|
95
|
+
exception.error_number if exception.respond_to?(:error_number)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
#--
|
|
99
|
+
# QUOTING ==================================================
|
|
100
|
+
#++
|
|
101
|
+
|
|
102
|
+
def quote_string(string)
|
|
103
|
+
@connection.escape(string)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
#--
|
|
107
|
+
# CONNECTION MANAGEMENT ====================================
|
|
108
|
+
#++
|
|
109
|
+
|
|
110
|
+
def active?
|
|
111
|
+
@connection.ping
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def reconnect!
|
|
115
|
+
super
|
|
116
|
+
disconnect!
|
|
117
|
+
connect
|
|
118
|
+
end
|
|
119
|
+
alias :reset! :reconnect!
|
|
120
|
+
|
|
121
|
+
# Disconnects from the database if already connected.
|
|
122
|
+
# Otherwise, this method does nothing.
|
|
123
|
+
def disconnect!
|
|
124
|
+
super
|
|
125
|
+
@connection.close
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def discard! # :nodoc:
|
|
129
|
+
super
|
|
130
|
+
@connection.automatic_close = false
|
|
131
|
+
@connection = nil
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def schema_creation
|
|
135
|
+
ActiveRecord::ConnectionAdapters::Singlestore::SchemaCreation.new(self)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def create_table_definition(name, **options)
|
|
139
|
+
ActiveRecord::ConnectionAdapters::Singlestore::TableDefinition.new(self, name, **options)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def extract_table_options!(options)
|
|
143
|
+
options.extract!(:temporary, :if_not_exists, :options, :as, :comment, :charset, :collation, :rowstore)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
private
|
|
147
|
+
|
|
148
|
+
def connect
|
|
149
|
+
@connection = Mysql2::Client.new(@config)
|
|
150
|
+
configure_connection
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def configure_connection
|
|
154
|
+
@connection.query_options[:as] = :array
|
|
155
|
+
super
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def full_version
|
|
159
|
+
schema_cache.database_version.full_version_string
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def get_full_version
|
|
163
|
+
@connection.server_info[:version]
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: activerecord-singlestore
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jens Dahl Mollerhoj
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2023-02-06 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.14'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.14'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: minitest
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '5.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '5.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: activerecord
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 6.0.0
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 6.0.0
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: mysql2
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: 0.4.4
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: 0.4.4
|
|
83
|
+
description: The ActiveRecod SinglestoreAdapter is an ActiveRecord connection adapter
|
|
84
|
+
based on the Mysql2 adapter.
|
|
85
|
+
email:
|
|
86
|
+
- mollerhoj3@gmail.com
|
|
87
|
+
executables: []
|
|
88
|
+
extensions: []
|
|
89
|
+
extra_rdoc_files: []
|
|
90
|
+
files:
|
|
91
|
+
- lib/active_record/connection_adapters/singlestore/schema_creation.rb
|
|
92
|
+
- lib/active_record/connection_adapters/singlestore/table_definition.rb
|
|
93
|
+
- lib/active_record/connection_adapters/singlestore_adapter.rb
|
|
94
|
+
homepage: https://github.com/mollerhoj/activerecord-single-store
|
|
95
|
+
licenses:
|
|
96
|
+
- MIT
|
|
97
|
+
metadata:
|
|
98
|
+
allowed_push_host: https://rubygems.org
|
|
99
|
+
post_install_message:
|
|
100
|
+
rdoc_options: []
|
|
101
|
+
require_paths:
|
|
102
|
+
- lib
|
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
|
+
requirements:
|
|
105
|
+
- - ">="
|
|
106
|
+
- !ruby/object:Gem::Version
|
|
107
|
+
version: '0'
|
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
|
+
requirements:
|
|
110
|
+
- - ">="
|
|
111
|
+
- !ruby/object:Gem::Version
|
|
112
|
+
version: '0'
|
|
113
|
+
requirements: []
|
|
114
|
+
rubygems_version: 3.4.1
|
|
115
|
+
signing_key:
|
|
116
|
+
specification_version: 4
|
|
117
|
+
summary: ActiveRecord SinglestoreAdapter
|
|
118
|
+
test_files: []
|