Module: BigQueryAdapter::SchemaStatements
- Included in:
- ActiveRecord::ConnectionAdapters::BigQueryAdapter
- Defined in:
- lib/big_query_adapter/schema_statements.rb
Overview
Includes helper methods
Instance Method Summary collapse
-
#columns(table_name, _name = nil) ⇒ Object
Returns an array of Column objects for the table specified by
table_name
. - #current_database ⇒ Object
- #foreign_keys(_table_name) ⇒ Object
-
#index_name(table_name, options) ⇒ Object
Ensure it’s shorter than the maximum identifier length for the current dbms.
-
#indexes(_table_name, _name = nil) ⇒ Object
Returns an array of indexes for the given table.
-
#primary_key(_table_name) ⇒ Object
Returns just a table’s primary key.
-
#tables(_name = nil) ⇒ Object
Returns an array of table names, for database tables visible on the current connection.
-
#views ⇒ Object
Returns an array of view names defined in the database.
Instance Method Details
#columns(table_name, _name = nil) ⇒ Object
Returns an array of Column objects for the table specified by table_name
. rubocop:disable Metrics/MethodLength, Metrics/AbcSize
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/big_query_adapter/schema_statements.rb', line 23 def columns(table_name, _name = nil) result = @connection.columns(table_name.to_s) result.each_with_object([]) do |field, cols| col_name = field.name col_sql_type = native_database_types.invert[name: field.type] col_nullable = (field.mode == 'NULLABLE') args = { sql_type: col_sql_type, type: col_sql_type, limit: nil } args[:scale] = nil args[:precision] = nil = ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(**args) cols << ActiveRecord::ConnectionAdapters::Column.new( col_name, nil, , col_nullable, table_name ) end end |
#current_database ⇒ Object
65 66 67 |
# File 'lib/big_query_adapter/schema_statements.rb', line 65 def current_database .database_name.strip end |
#foreign_keys(_table_name) ⇒ Object
54 55 56 |
# File 'lib/big_query_adapter/schema_statements.rb', line 54 def foreign_keys(_table_name) [] end |
#index_name(table_name, options) ⇒ Object
Ensure it’s shorter than the maximum identifier length for the current dbms
60 61 62 63 |
# File 'lib/big_query_adapter/schema_statements.rb', line 60 def index_name(table_name, ) maximum = .max_identifier_len || 255 super(table_name, )[0...maximum] end |
#indexes(_table_name, _name = nil) ⇒ Object
Returns an array of indexes for the given table.
16 17 18 |
# File 'lib/big_query_adapter/schema_statements.rb', line 16 def indexes(_table_name, _name = nil) [] end |
#primary_key(_table_name) ⇒ Object
Returns just a table’s primary key
50 51 52 |
# File 'lib/big_query_adapter/schema_statements.rb', line 50 def primary_key(_table_name) [] end |
#tables(_name = nil) ⇒ Object
Returns an array of table names, for database tables visible on the current connection.
6 7 8 |
# File 'lib/big_query_adapter/schema_statements.rb', line 6 def tables(_name = nil) raw_connection.tables end |
#views ⇒ Object
Returns an array of view names defined in the database.
11 12 13 |
# File 'lib/big_query_adapter/schema_statements.rb', line 11 def views [] end |