Class: Baza::Driver::Mysql::Database

Inherits:
Baza::Database show all
Defined in:
lib/baza/driver/mysql/database.rb

Instance Attribute Summary

Attributes inherited from Baza::Database

#db, #driver, #name

Instance Method Summary collapse

Methods inherited from Baza::Database

#import_file!, #initialize, #name_changed?, #name_was, #table, #table_exists?, #tables, #to_param, #use

Methods included from Baza::DatabaseModelFunctionality

#model_name, #to_model

Constructor Details

This class inherits a constructor from Baza::Database

Instance Method Details

#create_table(name, columns:, indexes: nil, return_sql: false, temp: false) ⇒ Object

Creates a new table by the given name and data.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/baza/driver/mysql/database.rb', line 14

def create_table(name, columns:, indexes: nil, return_sql: false, temp: false)
  raise "No columns was given for '#{name}'." if !columns || columns.empty?

  sql = Baza::Driver::Mysql::Sql::CreateTable
    .new(
      columns: columns,
      indexes: indexes,
      name: name,
      temporary: temp
    )
    .sql

  return sql if return_sql

  use do
    sql.each do |sql_i|
      @db.query(sql_i)
    end
  end
end

#dropObject



7
8
9
10
11
# File 'lib/baza/driver/mysql/database.rb', line 7

def drop
  sql = "DROP DATABASE #{@db.quote_database(name)}"
  @db.query(sql)
  self
end

#save!Object



2
3
4
5
# File 'lib/baza/driver/mysql/database.rb', line 2

def save!
  rename(name) unless name.to_s == name_was
  self
end