Class: ActiveRecord::ConnectionAdapters::TidbAdapter
- Inherits:
-
Mysql2Adapter
- Object
- Mysql2Adapter
- ActiveRecord::ConnectionAdapters::TidbAdapter
show all
- Includes:
- Sequence::Adapter
- Defined in:
- lib/active_record/connection_adapters/tidb_adapter.rb
Constant Summary
collapse
- ADAPTER_NAME =
'Tidb'
Class Method Summary
collapse
Instance Method Summary
collapse
#check_sequences, #create_sequence, #drop_sequence, #recreate_sequence
Constructor Details
#initialize(connection, logger, conn_params, config) ⇒ TidbAdapter
Returns a new instance of TidbAdapter.
86
87
88
89
90
91
|
# File 'lib/active_record/connection_adapters/tidb_adapter.rb', line 86
def initialize(connection, logger, conn_params, config)
super(connection, logger, conn_params, config)
tidb_version_string = query_value('select version()')
@tidb_version = tidb_version_string[/TiDB-v([0-9.]+)/, 1]
end
|
Class Method Details
.database_exists?(config) ⇒ Boolean
101
102
103
104
105
|
# File 'lib/active_record/connection_adapters/tidb_adapter.rb', line 101
def self.database_exists?(config)
!ActiveRecord::Base.tidb_connection(config).nil?
rescue ActiveRecord::NoDatabaseError
false
end
|
Instance Method Details
#new_column_from_field(_table_name, field) ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/active_record/connection_adapters/tidb_adapter.rb', line 107
def new_column_from_field(_table_name, field)
type_metadata = fetch_type_metadata(field[:Type], field[:Extra])
default = field[:Default]
default_function = nil
if type_metadata.type == :datetime && /\ACURRENT_TIMESTAMP(?:\([0-6]?\))?\z/i.match?(default)
default = "#{default} ON UPDATE #{default}" if /on update CURRENT_TIMESTAMP/i.match?(field[:Extra])
default_function = default
default = nil
elsif type_metadata. == 'DEFAULT_GENERATED'
default = +"(#{default})" unless default.start_with?('(')
default_function = default
default = nil
elsif default.to_s =~ /nextval/i
default_function = default
default = nil
end
MySQL::Column.new(
field[:Field],
default,
type_metadata,
field[:Null] == 'YES',
default_function,
collation: field[:Collation],
comment: field[:Comment].presence
)
end
|
#supports_advisory_locks? ⇒ Boolean
55
56
57
58
|
# File 'lib/active_record/connection_adapters/tidb_adapter.rb', line 55
def supports_advisory_locks?
false
end
|
#supports_bulk_alter? ⇒ Boolean
50
51
52
53
|
# File 'lib/active_record/connection_adapters/tidb_adapter.rb', line 50
def supports_bulk_alter?
false
end
|
#supports_common_table_expressions? ⇒ Boolean
82
83
84
|
# File 'lib/active_record/connection_adapters/tidb_adapter.rb', line 82
def supports_common_table_expressions?
tidb_version >= '5.1.0'
end
|
#supports_expression_index? ⇒ Boolean
73
74
75
76
77
78
79
80
|
# File 'lib/active_record/connection_adapters/tidb_adapter.rb', line 73
def supports_expression_index?
sql = <<~SQL
SELECT VALUE
FROM INFORMATION_SCHEMA.CLUSTER_CONFIG
WHERE `KEY` = 'experimental.allow-expression-index' AND `TYPE` = 'tidb'
SQL
query_value(sql) == 'true'
end
|
#supports_foreign_keys? ⇒ Boolean
45
46
47
48
|
# File 'lib/active_record/connection_adapters/tidb_adapter.rb', line 45
def supports_foreign_keys?
false
end
|
#supports_index_sort_order? ⇒ Boolean
68
69
70
71
|
# File 'lib/active_record/connection_adapters/tidb_adapter.rb', line 68
def supports_index_sort_order?
false
end
|
#supports_json? ⇒ Boolean
64
65
66
|
# File 'lib/active_record/connection_adapters/tidb_adapter.rb', line 64
def supports_json?
true
end
|
#supports_optimizer_hints? ⇒ Boolean
60
61
62
|
# File 'lib/active_record/connection_adapters/tidb_adapter.rb', line 60
def supports_optimizer_hints?
true
end
|
#supports_savepoints? ⇒ Boolean
40
41
42
43
|
# File 'lib/active_record/connection_adapters/tidb_adapter.rb', line 40
def supports_savepoints?
false
end
|
#tidb_version ⇒ Object
97
98
99
|
# File 'lib/active_record/connection_adapters/tidb_adapter.rb', line 97
def tidb_version
Version.new(tidb_version_string)
end
|
#tidb_version_string ⇒ Object
93
94
95
|
# File 'lib/active_record/connection_adapters/tidb_adapter.rb', line 93
def tidb_version_string
@tidb_version
end
|