Class: ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/arql/ext/active_record/connection_adapters/abstract_mysql_adapter.rb

Instance Method Summary collapse

Instance Method Details

#extract_schema_qualified_name_of_tables(table_names) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/arql/ext/active_record/connection_adapters/abstract_mysql_adapter.rb', line 7

def extract_schema_qualified_name_of_tables(table_names)
  table_names.map do |string|
    schema, name = string.to_s.scan(/[^`.\s]+|`[^`]*`/)
    schema, name = nil, schema unless name
    [schema, name]
  end
end

#primary_keys_of_tables(table_names) ⇒ Object

:nodoc:

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/arql/ext/active_record/connection_adapters/abstract_mysql_adapter.rb', line 24

def primary_keys_of_tables(table_names) # :nodoc:
  raise ArgumentError unless table_names.present?

  scopes = quoted_scope_of_tables(table_names)

  res = query("  SELECT table_name, column_name\n  FROM information_schema.statistics\n  WHERE index_name = 'PRIMARY'\n  AND (table_schema, table_name) in\n  (\#{scopes.map { |scope| \"(\#{scope[:schema]}, \#{scope[:name]})\" }.join(', ')})\n    ORDER BY seq_in_index\n  SQL\n\n  res.group_by(&:first).map { |table, vlaues| [table, vlaues.map(&:last)] }.to_h\nend\n", "SCHEMA")

#quoted_scope_of_tables(names = nil) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/arql/ext/active_record/connection_adapters/abstract_mysql_adapter.rb', line 15

def quoted_scope_of_tables(names = nil)
  extract_schema_qualified_name_of_tables(names).map do |(schema, name)|
    scope = {}
    scope[:schema] = schema ? quote(schema) : "database()"
    scope[:name] = quote(name) if name
    scope
  end
end

#table_comment_of_tables(table_names) ⇒ Object

:nodoc:



41
42
43
44
45
46
47
48
49
50
# File 'lib/arql/ext/active_record/connection_adapters/abstract_mysql_adapter.rb', line 41

def table_comment_of_tables(table_names) # :nodoc:
  scopes = quoted_scope_of_tables(table_names)

  query("  SELECT table_name, table_comment\n  FROM information_schema.tables\n  WHERE (table_schema, table_name) in\n  (\#{scopes.map { |scope| \"(\#{scope[:schema]}, \#{scope[:name]})\" }.join(', ')})\n  SQL\nend\n", "SCHEMA").presence.try(&:to_h)