Class: Sequel::Amalgalite::SequelTypeMap
- Inherits:
-
Amalgalite::TypeMaps::DefaultMap
- Object
- Amalgalite::TypeMaps::DefaultMap
- Sequel::Amalgalite::SequelTypeMap
- Defined in:
- lib/sequel/adapters/amalgalite.rb
Overview
Type conversion map class for Sequel’s use of Amalgamite
Instance Method Summary collapse
-
#blob(s) ⇒ Object
Return blobs as instances of Sequel::SQL::Blob instead of Amalgamite::Blob.
-
#datetime(s) ⇒ Object
Return datetime types as instances of Sequel.datetime_class.
-
#decimal(s) ⇒ Object
Return numeric/decimal types as instances of BigDecimal instead of Float.
-
#initialize(db) ⇒ SequelTypeMap
constructor
Store the related database object, in order to be able to correctly handle the database timezone.
-
#result_value_of(declared_type, value) ⇒ Object
Don’t raise an error if the value is a string and the declared type doesn’t match a known type, just return the value.
- #time(s) ⇒ Object
Constructor Details
#initialize(db) ⇒ SequelTypeMap
Store the related database object, in order to be able to correctly handle the database timezone.
20 21 22 |
# File 'lib/sequel/adapters/amalgalite.rb', line 20 def initialize(db) @db = db end |
Instance Method Details
#blob(s) ⇒ Object
Return blobs as instances of Sequel::SQL::Blob instead of Amalgamite::Blob
26 27 28 |
# File 'lib/sequel/adapters/amalgalite.rb', line 26 def blob(s) SQL::Blob.new(s) end |
#datetime(s) ⇒ Object
Return datetime types as instances of Sequel.datetime_class
37 38 39 |
# File 'lib/sequel/adapters/amalgalite.rb', line 37 def datetime(s) @db.(s) end |
#decimal(s) ⇒ Object
Return numeric/decimal types as instances of BigDecimal instead of Float
32 33 34 |
# File 'lib/sequel/adapters/amalgalite.rb', line 32 def decimal(s) BigDecimal.new(s) end |
#result_value_of(declared_type, value) ⇒ Object
Don’t raise an error if the value is a string and the declared type doesn’t match a known type, just return the value.
47 48 49 50 51 52 53 54 55 |
# File 'lib/sequel/adapters/amalgalite.rb', line 47 def result_value_of(declared_type, value) if value.is_a?(::Amalgalite::Blob) SQL::Blob.new(value.to_s) elsif value.is_a?(String) && declared_type (meth = self.class.sql_to_method(declared_type.downcase)) ? send(meth, value) : value else super end end |
#time(s) ⇒ Object
41 42 43 |
# File 'lib/sequel/adapters/amalgalite.rb', line 41 def time(s) Sequel.string_to_time(s) end |