Class: Simmer::Externals::MysqlDatabase

Inherits:
Object
  • Object
show all
Defined in:
lib/simmer/externals/mysql_database.rb

Overview

Provides a wrapper around mysql2 for Simmer.

Constant Summary collapse

DATABASE_SUFFIX =
'_test'

Instance Method Summary collapse

Constructor Details

#initialize(client, exclude_tables = []) ⇒ MysqlDatabase

Returns a new instance of MysqlDatabase.



18
19
20
21
22
23
24
25
26
27
# File 'lib/simmer/externals/mysql_database.rb', line 18

def initialize(client, exclude_tables = [])
  @client = client

  assert_database_name(schema)

  exclude_tables = Array(exclude_tables).map(&:to_s)
  @table_names   = retrieve_table_names - exclude_tables

  freeze
end

Instance Method Details

#clean!Object



43
44
45
46
47
48
49
# File 'lib/simmer/externals/mysql_database.rb', line 43

def clean!
  sql_statements = clean_sql_statements

  shameless_execute(sql_statements)

  sql_statements.length
end

#records(table, columns = []) ⇒ Object



29
30
31
32
33
# File 'lib/simmer/externals/mysql_database.rb', line 29

def records(table, columns = [])
  query = "SELECT #{sql_select_params(columns)} FROM #{qualify(table)}"

  client.query(query).to_a
end

#seed!(fixtures) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/simmer/externals/mysql_database.rb', line 35

def seed!(fixtures)
  sql_statements = seed_sql_statements(fixtures)

  shameless_execute(sql_statements)

  sql_statements.length
end