Created
November 16, 2009 08:57
-
-
Save macks/235868 to your computer and use it in GitHub Desktop.
Column-level collation support for DataMapper/MySQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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