Class: Rails::Sequel::Database::Mysql

Inherits:
Object
  • Object
show all
Defined in:
lib/rails3_sequel/adapters/mysql.rb

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Mysql

Returns a new instance of Mysql.



6
7
8
9
# File 'lib/rails3_sequel/adapters/mysql.rb', line 6

def initialize (env)
  @env = env
  @config = Database.configurations[@env]
end

Instance Method Details

#connect(options = {}) ⇒ Object



11
12
13
# File 'lib/rails3_sequel/adapters/mysql.rb', line 11

def connect (options = {})
  ::Sequel.connect(@config.merge(options))
end

#create_database(options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/rails3_sequel/adapters/mysql.rb', line 15

def create_database (options = {})
  db = management_connect
  name = @config['database']

  if options[:collation]
    db.execute "CREATE DATABASE `#{name}` DEFAULT CHARACTER SET `#{options[:charset] || 'utf8'}` COLLATE `#{options[:collation]}`"
  else
    db.execute "CREATE DATABASE `#{name}` DEFAULT CHARACTER SET `#{options[:charset] || 'utf8'}`"
  end 
end

#drop_databaseObject



26
27
28
29
30
# File 'lib/rails3_sequel/adapters/mysql.rb', line 26

def drop_database
  db = management_connect
  name = @config['database']
  db.execute "DROP DATABASE IF EXISTS `#{name}`"
end