Sha256: b11e1ae8efaf7933db7ae9d38d5cdebfa7b22ba4107906b6c16d85266101f605

Contents?: true

Size: 1015 Bytes

Versions: 2

Compression:

Stored size: 1015 Bytes

Contents

module Rails
  module Sequel
    class Database

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

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

        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

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

        private

        def management_connect
          connect('database' => nil)
        end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails3_sequel-0.3.1 lib/rails3_sequel/adapters/mysql.rb
rails3_sequel-0.3.0 lib/rails3_sequel/adapters/mysql.rb