Created
August 29, 2013 23:32
-
-
Save tpendragon/6384687 to your computer and use it in GitHub Desktop.
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
# Monkey patch in requiring nsec as the cache timestamp format. | |
module ActiveRecord | |
class Base | |
self.cache_timestamp_format = :nsec | |
end | |
end | |
module ActiveRecord | |
module ConnectionAdapters | |
class Mysql2Adapter < AbstractMysqlAdapter | |
def type_to_sql(type, limit=nil, precision=nil, scale=nil) | |
case type.to_s | |
when 'datetime' | |
return super unless precision | |
case precision | |
when 0..6; "datetime(#{precision})" | |
else raise(ActiveRecordError, "No timestamp type has precision of #{precision}. The allowed range of precision is from 0 to 6") | |
end | |
else | |
super | |
end | |
end | |
def quoted_date(value) | |
if value.acts_like?(:time) && value.respond_to?(:usec) | |
"#{super}.#{sprintf("%06d", value.usec)}" | |
else | |
super | |
end | |
end | |
private | |
def extract_limit(sql_type) | |
case sql_type | |
when /^timestamp/i; nil | |
else super | |
end | |
end | |
def extract_precision(sql_type) | |
if sql_type =~ /timestamp/i | |
$1.to_i if sql_type =~ /\((\d+)\)/ | |
else | |
super | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment