Skip to content

Instantly share code, notes, and snippets.

@macks
Created November 16, 2009 08:57
Show Gist options
  • Select an option

  • Save macks/235868 to your computer and use it in GitHub Desktop.

Select an option

Save macks/235868 to your computer and use it in GitHub Desktop.
Column-level collation support for DataMapper/MySQL
# Column-level collation support for DataMapper/MySQL
#
# e.g.)
# property :name, String, :collate => 'utf8_bin'
gem 'dm-core', '0.10.0'
require 'dm-core'
require 'dm-core/adapters/mysql_adapter'
module DataMapper
Property::OPTIONS << :collate
module Adapters
class DataObjectsAdapter
alias property_schema_hash__without_collate property_schema_hash
alias property_schema_statement__without_collate property_schema_statement
end
class MysqlAdapter
alias property_schema_hash__without_collate property_schema_hash
alias property_schema_statement__without_collate property_schema_statement
def property_schema_hash(property)
schema = property_schema_hash__without_collate(property)
schema[:collate] = property.options[:collate] if property.options[:collate]
schema
end
def property_schema_statement(connection, schema)
statement = property_schema_statement__without_collate(connection, schema)
statement << " COLLATE #{schema[:collate]}" if schema[:collate]
statement
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment