Sha256: 90c1da953c99720f5b99ee233b9d848b79f6ab7ed1c0ed6a2f2286880a1a7d19

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

require 'data_mapper/adapters/data_object_adapter'
begin
  require 'do_mysql'
rescue LoadError
  STDERR.puts <<-EOS
You must install the DataObjects::Mysql driver.
  gem install do_mysql
EOS
  exit
end

module DataMapper
  module Adapters
    
    class MysqlAdapter < DataObjectAdapter
      def create_connection
        
        connection_string = ""
        builder = lambda { |k,v| connection_string << "#{k}=#{@configuration.send(v)} " unless @configuration.send(v).blank? }
        
        builder['host', :host]
        builder['user', :username]
        builder['password', :password]
        builder['dbname', :database]
        builder['socket', :socket]
        
        logger.debug { connection_string.strip }
        
        conn = DataObject::Mysql::Connection.new(connection_string.strip)
        conn.logger = self.logger
        conn.open
        cmd = conn.create_command("SET NAMES UTF8")
        cmd.execute_non_query
        return conn
      end
      
      def database_column_name
        "TABLE_SCHEMA"
      end
      
      module Mappings
        
        def to_create_table_sql
          @to_create_table_sql || @to_create_table_sql = begin
            "CREATE TABLE #{to_sql} (#{columns.map { |c| c.to_long_form }.join(', ')}) Type=MyISAM CHARACTER SET utf8"
          end
        end
        
        class Schema

          def database_tables
            get_database_tables(@adapter.schema.name)
          end

        end

        
      end # module Mappings
    end # class MysqlAdapter
    
  end # module Adapters
end # module DataMapper

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
datamapper-0.2.4 lib/data_mapper/adapters/mysql_adapter.rb