### Home Classes Methods

### In Files

- lib/amalgalite/type_maps/default_map.rb

### Parent

Object

### Methods

- ::new
- #bind_type_of
- #blob
- #boolean
- #date
- #datetime
- #float
- #integer
- #result_value_of
- #string
- #time

### Files

- HISTORY.rdoc
- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- Amalgalite
- Amalgalite::Aggregate
- Amalgalite::Blob
- Amalgalite::Blob::Error
- Amalgalite::Boolean
- Amalgalite::BusyHandler
- Amalgalite::BusyTimeout
- Amalgalite::CSVTableImporter
- Amalgalite::Column
- Amalgalite::Database
- Amalgalite::Database::AggregateError
- Amalgalite::Database::BusyHandlerError
- Amalgalite::Database::FunctionError
- Amalgalite::Database::InvalidModeError
- Amalgalite::Database::ProgressHandlerError
- Amalgalite::Database::TransactionBehavior
- Amalgalite::Error
- Amalgalite::Function
- Amalgalite::Index
- Amalgalite::MemoryDatabase
- Amalgalite::Packer
- Amalgalite::Paths
- Amalgalite::ProfileSampler
- Amalgalite::ProfileTap
- Amalgalite::ProgressHandler
- Amalgalite::Requires
- Amalgalite::SQLite3
- Amalgalite::SQLite3::Constants
- Amalgalite::SQLite3::Constants::Config
- Amalgalite::SQLite3::Constants::DBStatus
- Amalgalite::SQLite3::Constants::DataType
- Amalgalite::SQLite3::Constants::Helpers
- Amalgalite::SQLite3::Constants::Open
- Amalgalite::SQLite3::Constants::ResultCode
- Amalgalite::SQLite3::Constants::StatementStatus
- Amalgalite::SQLite3::Constants::Status
- Amalgalite::SQLite3::Database
- Amalgalite::SQLite3::Database::DBStatus
- Amalgalite::SQLite3::Database::Function
- Amalgalite::SQLite3::Database::Stat
- Amalgalite::SQLite3::Stat
- Amalgalite::SQLite3::Status
- Amalgalite::SQLite3::Version
- Amalgalite::Schema
- Amalgalite::Statement
- Amalgalite::Table
- Amalgalite::Taps
- Amalgalite::Taps::IO
- Amalgalite::Taps::Stderr
- Amalgalite::Taps::Stdout
- Amalgalite::Taps::StringIO
- Amalgalite::TraceTap
- Amalgalite::TypeMap
- Amalgalite::TypeMaps
- Amalgalite::TypeMaps::DefaultMap
- Amalgalite::TypeMaps::StorageMap
- Amalgalite::TypeMaps::TextMap
- Amalgalite::Version
- Amalgalite::View
- Kernel
- Object

No matching classes.

# Amalgalite::TypeMaps::DefaultMap

An Amalgalite::TypeMap that does its best to convert between Ruby classes and known SQL data types.

Upon instantiation, DefaultMap generates a conversion map to try to figure out the best way to convert between populate SQL 'types' and ruby classes

### Public Class Methods

new() click to toggle source

    # File lib/amalgalite/type_maps/default_map.rb, line 58
    def initialize
    end

### Public Instance Methods

bind_type_of( obj ) click to toggle source

A straight logical mapping (for me at least) of basic Ruby classes to SQLite types, if nothing can be found then default to TEXT.

    # File lib/amalgalite/type_maps/default_map.rb, line 65
    def bind_type_of( obj )
      case obj
      when Float
        ::Amalgalite::SQLite3::Constants::DataType::FLOAT
      when Fixnum
        ::Amalgalite::SQLite3::Constants::DataType::INTEGER
      when NilClass
        ::Amalgalite::SQLite3::Constants::DataType::NULL
      when ::Amalgalite::Blob
        ::Amalgalite::SQLite3::Constants::DataType::BLOB
      else
        ::Amalgalite::SQLite3::Constants::DataType::TEXT
      end
    end

blob( str ) click to toggle source

convert a string to a blob

    # File lib/amalgalite/type_maps/default_map.rb, line 163
    def blob( str )
      ::Amalgalite::Blob.new( :string => str )
    end

boolean( str ) click to toggle source

convert a string to true of false

    # File lib/amalgalite/type_maps/default_map.rb, line 156
    def boolean( str )
      ::Amalgalite::Boolean.to_bool( str )
    end

date( str ) click to toggle source

convert a string to a date

    # File lib/amalgalite/type_maps/default_map.rb, line 113
    def date( str )
      Date.parse( str )
    end

datetime( str ) click to toggle source

convert a string to a datetime, if no timzone is found in the parsed string, set it to the local offset.

    # File lib/amalgalite/type_maps/default_map.rb, line 121
    def datetime( str )
      DateTime.parse( str )
    end

float( str ) click to toggle source

convert a string to a Float

    # File lib/amalgalite/type_maps/default_map.rb, line 135
    def float( str )
      Float( str )
    end

integer( str ) click to toggle source

convert an string to an Integer

    # File lib/amalgalite/type_maps/default_map.rb, line 142
    def integer( str )
      Float( str ).to_i
    end

result_value_of( declared_type, value ) click to toggle source

Map the incoming value to an outgoing value. For some incoming values, there will be no change, but for some (i.e. Dates and Times) there is some conversion

    # File lib/amalgalite/type_maps/default_map.rb, line 85
    def result_value_of( declared_type, value )
      case value
      when Numeric
        return value
      when NilClass
        return value
      when Amalgalite::Blob
        return value
      when String
        if declared_type then
          conversion_method = DefaultMap.sql_to_method( declared_type.downcase )
          if conversion_method then
            return send(conversion_method, value)
          else
            raise ::Amalgalite::Error, "Unable to convert SQL type of #{declared_type} to a Ruby class"
          end
        else
          # unable to do any other conversion, just return what we have.
          return value
        end
      else
        raise ::Amalgalite::Error, "Unable to convert a class #{value.class.name} with value #{value.inspect}"
      end
    end

string( str ) click to toggle source

convert a string to a String, yes redundant I know.

    # File lib/amalgalite/type_maps/default_map.rb, line 149
    def string( str )
      str
    end

time( str ) click to toggle source

convert a string to a Time

    # File lib/amalgalite/type_maps/default_map.rb, line 128
    def time( str )
      Time.parse( str )
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.