Class: Rails::Sequel::Database::Mysql
- Inherits:
-
Object
- Object
- Rails::Sequel::Database::Mysql
- Defined in:
- lib/rails3_sequel/adapters/mysql.rb
Instance Method Summary collapse
- #connect(options = {}) ⇒ Object
- #create_database(options = {}) ⇒ Object
- #drop_database ⇒ Object
-
#initialize(env) ⇒ Mysql
constructor
A new instance of Mysql.
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 ( = {}) ::Sequel.connect(@config.merge()) 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 ( = {}) db = management_connect name = @config['database'] if [:collation] db.execute "CREATE DATABASE `#{name}` DEFAULT CHARACTER SET `#{[:charset] || 'utf8'}` COLLATE `#{[:collation]}`" else db.execute "CREATE DATABASE `#{name}` DEFAULT CHARACTER SET `#{[:charset] || 'utf8'}`" end end |
#drop_database ⇒ Object
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 |