Module: Sequel::SQLite

Defined in:
lib/sequel/adapters/sqlite.rb,
lib/sequel/adapters/shared/sqlite.rb

Overview

Top level module for holding all SQLite-related modules and classes for Sequel.

Defined Under Namespace

Modules: DatabaseMethods, DatasetMethods Classes: Database, Dataset

Constant Summary

TYPE_TRANSLATOR =
tt = Class.new do
  FALSE_VALUES = (%w'0 false f no n' + [0]).freeze

  def blob(s)
    Sequel::SQL::Blob.new(s.to_s)
  end

  def boolean(s)
    s = s.downcase if s.is_a?(String)
    !FALSE_VALUES.include?(s)
  end

  def date(s)
    case s
    when String
      Sequel.string_to_date(s)
    when Integer
      Date.jd(s)
    when Float
      Date.jd(s.to_i)
    else
      raise Sequel::Error, "unhandled type when converting to date: #{s.inspect} (#{s.class.inspect})"
    end
  end

  def integer(s)
    s.to_i
  end

  def float(s)
    s.to_f
  end

  def numeric(s)
    s = s.to_s unless s.is_a?(String)
    ::BigDecimal.new(s) rescue s
  end

  def time(s)
    case s
    when String
      Sequel.string_to_time(s)
    when Integer
      Sequel::SQLTime.create(s/3600, (s % 3600)/60, s % 60)
    when Float
      s, f = s.divmod(1)
      Sequel::SQLTime.create(s/3600, (s % 3600)/60, s % 60, (f*1000000).round)
    else
      raise Sequel::Error, "unhandled type when converting to date: #{s.inspect} (#{s.class.inspect})"
    end
  end

end.new
SQLITE_TYPES =

Hash with string keys and callable values for converting SQLite types.

{}