class Purview::Databases::MySQL

Private Instance Methods

connection_type() click to toggle source
# File lib/purview/databases/mysql.rb, line 6
def connection_type
  Purview::Connections::MySQL
end
create_index_sql(table_name, index_name, index, index_opts={}) click to toggle source
# File lib/purview/databases/mysql.rb, line 10
def create_index_sql(table_name, index_name, index, index_opts={})
  'CREATE%sINDEX %s ON %s (%s)' % [
    index.unique? ? ' UNIQUE ' : ' ',
    index_name,
    table_name,
    column_names(index).join(', '),
  ]
end
create_table_sql(table_name, table, table_opts={}) click to toggle source
# File lib/purview/databases/mysql.rb, line 19
def create_table_sql(table_name, table, table_opts={})
  'CREATE TABLE %s (%s)' % [
    table_name,
    column_definitions(table).join(', '),
  ]
end
create_temporary_table_sql(table_name, table, table_opts={}) click to toggle source
# File lib/purview/databases/mysql.rb, line 26
def create_temporary_table_sql(table_name, table, table_opts={})
  'CREATE TEMPORARY TABLE %s LIKE %s' % [
    table_name,
    table.name,
  ]
end
default_map() click to toggle source
Calls superclass method Purview::Databases::Base#default_map
# File lib/purview/databases/mysql.rb, line 33
def default_map
  super.merge(Purview::Types::Timestamp => '0')
end
dialect_type() click to toggle source
# File lib/purview/databases/mysql.rb, line 37
def dialect_type
  Purview::Dialects::MySQL
end
disable_table_sql(table) click to toggle source
# File lib/purview/databases/mysql.rb, line 41
def disable_table_sql(table)
  'UPDATE %s SET %s = %s, %s = %s WHERE %s = %s AND %s IS NOT NULL' % [
    table_metadata_table.name,
    table_metadata_table.enabled_at_column.name,
    null_value,
    table_metadata_table.last_updated_at_column.name,
    quoted(Time.now),
    table_metadata_table.table_name_column.name,
    quoted(table.name),
    table_metadata_table.enabled_at_column.name,
  ]
end
drop_index_sql(table_name, index_name, index, index_opts={}) click to toggle source
# File lib/purview/databases/mysql.rb, line 54
def drop_index_sql(table_name, index_name, index, index_opts={})
  'DROP INDEX %s' % [
    index_name,
  ]
end
drop_table_sql(table_name, table, table_opts={}) click to toggle source
# File lib/purview/databases/mysql.rb, line 60
def drop_table_sql(table_name, table, table_opts={})
  'DROP TABLE %s' % [
    table_name,
  ]
end
enable_table_sql(table, timestamp) click to toggle source
# File lib/purview/databases/mysql.rb, line 66
def enable_table_sql(table, timestamp)
  'UPDATE %s SET %s = %s, %s = %s WHERE %s = %s AND %s IS NULL' % [
    table_metadata_table.name,
    table_metadata_table.enabled_at_column.name,
    quoted(timestamp),
    table_metadata_table.last_updated_at_column.name,
    quoted(Time.now),
    table_metadata_table.table_name_column.name,
    quoted(table.name),
    table_metadata_table.enabled_at_column.name,
  ]
end
ensure_table_metadata_absent_for_table_sql(table) click to toggle source
# File lib/purview/databases/mysql.rb, line 79
def ensure_table_metadata_absent_for_table_sql(table)
  'DELETE FROM %s WHERE %s = %s' % [
    table_metadata_table.name,
    table_metadata_table.table_name_column.name,
    quoted(table.name),
  ]
end
ensure_table_metadata_exists_for_table_sql(table) click to toggle source
# File lib/purview/databases/mysql.rb, line 87
def ensure_table_metadata_exists_for_table_sql(table)
  'INSERT IGNORE INTO %s VALUES (%s, NULL, NULL, NULL, NULL, NULL)' % [
    table_metadata_table.name,
    quoted(table.name),
  ]
end
ensure_table_metadata_table_exists_sql() click to toggle source
# File lib/purview/databases/mysql.rb, line 94
def ensure_table_metadata_table_exists_sql
  'CREATE TABLE IF NOT EXISTS %s (%s)' % [
    table_metadata_table.name,
    column_definitions(table_metadata_table).join(', '),
  ]
end
get_table_metadata_value_sql(table, column) click to toggle source
# File lib/purview/databases/mysql.rb, line 114
def get_table_metadata_value_sql(table, column)
  'SELECT %s FROM %s WHERE %s = %s' % [
    column.name,
    table_metadata_table.name,
    table_metadata_table.table_name_column.name,
    quoted(table.name),
  ]
end
initialize_table_sql(table, timestamp) click to toggle source
# File lib/purview/databases/mysql.rb, line 101
def initialize_table_sql(table, timestamp)
  'UPDATE %s SET %s = %s, %s = %s WHERE %s = %s AND %s IS NULL' % [
    table_metadata_table.name,
    table_metadata_table.max_timestamp_pulled_column.name,
    quoted(timestamp),
    table_metadata_table.last_updated_at_column.name,
    quoted(Time.now),
    table_metadata_table.table_name_column.name,
    quoted(table.name),
    table_metadata_table.max_timestamp_pulled_column.name,
  ]
end
limit_map() click to toggle source
Calls superclass method Purview::Databases::Base#limit_map
# File lib/purview/databases/mysql.rb, line 123
def limit_map
  super.merge(Purview::Types::String => 255)
end
lock_table_sql(table, timestamp) click to toggle source
# File lib/purview/databases/mysql.rb, line 127
def lock_table_sql(table, timestamp)
  'UPDATE %s SET %s = %s, %s = %s WHERE %s = %s AND %s IS NULL' % [
    table_metadata_table.name,
    table_metadata_table.locked_at_column.name,
    quoted(timestamp),
    table_metadata_table.last_updated_at_column.name,
    quoted(Time.now),
    table_metadata_table.table_name_column.name,
    quoted(table.name),
    table_metadata_table.locked_at_column.name,
  ]
end
next_table_sql(timestamp) click to toggle source
# File lib/purview/databases/mysql.rb, line 140
def next_table_sql(timestamp)
  'SELECT %s FROM %s WHERE %s IS NOT NULL AND %s IS NOT NULL AND %s IS NULL ORDER BY %s IS NULL DESC, %s LIMIT 1' % [
    table_metadata_table.table_name_column.name,
    table_metadata_table.name,
    table_metadata_table.enabled_at_column.name,
    table_metadata_table.max_timestamp_pulled_column.name,
    table_metadata_table.locked_at_column.name,
    table_metadata_table.last_pulled_at_column.name,
    table_metadata_table.last_pulled_at_column.name,
  ]
end
set_table_metadata_value_sql(table, column, value) click to toggle source
# File lib/purview/databases/mysql.rb, line 152
def set_table_metadata_value_sql(table, column, value)
  'UPDATE %s SET %s = %s, %s = %s WHERE %s = %s' % [
    table_metadata_table.name,
    column.name,
    quoted(value),
    table_metadata_table.last_updated_at_column.name,
    quoted(Time.now),
    table_metadata_table.table_name_column.name,
    quoted(table.name),
  ]
end
type_map() click to toggle source
Calls superclass method Purview::Databases::Base#type_map
# File lib/purview/databases/mysql.rb, line 164
def type_map
  super.merge(
    Purview::Types::Money => 'decimal',
    Purview::Types::UUID => 'varchar',
  )
end
unlock_table_sql(table) click to toggle source
# File lib/purview/databases/mysql.rb, line 171
def unlock_table_sql(table)
  'UPDATE %s SET %s = %s, %s = %s WHERE %s = %s AND %s IS NOT NULL' % [
    table_metadata_table.name,
    table_metadata_table.locked_at_column.name,
    null_value,
    table_metadata_table.last_updated_at_column.name,
    quoted(Time.now),
    table_metadata_table.table_name_column.name,
    quoted(table.name),
    table_metadata_table.locked_at_column.name,
  ]
end