Class | Sequel::SQLite::Database
In: | lib/sequel/adapters/sqlite.rb
Parent: | Sequel::Database

Database class for SQLite databases used with Sequel and the ruby-sqlite3 driver.

### Methods

connect dataset execute execute_dui execute_insert single_value

### Included Modules

::Sequel::SQLite::DatabaseMethods

### Constants

UNIX_EPOCH_TIME_FORMAT | = | /\A\d+\z/.freeze

### Public Instance methods

connect(server)

Connect to the database. Since SQLite is a file based database, the only options available are :database (to specify the database name), and :timeout, to specify how long to wait for the database to be available if it is locked, given in milliseconds (default is 5000).

[Source]

        # File lib/sequel/adapters/sqlite.rb, line 28
    28:       def connect(server)
    29:         opts = server_opts(server)
    30:         opts[:database] = ':memory:' if blank_object?(opts[:database])
    31:         db = ::SQLite3::Database.new(opts[:database])
    32:         db.busy_timeout(opts.fetch(:timeout, 5000))
    33:         db.type_translation = true
    34:
    35:         # Handle datetimes with Sequel.datetime_class
    36:         prok = proc do |t,v|
    37:           v = Time.at(v.to_i).iso8601 if UNIX_EPOCH_TIME_FORMAT.match(v)
    38:           Sequel.database_to_application_timestamp(v)
    39:         end
    40:         db.translator.add_translator("timestamp", &prok)
    41:         db.translator.add_translator("datetime", &prok)
    42:
    43:         # Handle numeric values with BigDecimal
    44:         prok = proc{|t,v| BigDecimal.new(v) rescue v}
    45:         db.translator.add_translator("numeric", &prok)
    46:         db.translator.add_translator("decimal", &prok)
    47:         db.translator.add_translator("money", &prok)
    48:
    49:         # Handle floating point values with Float
    50:         prok = proc{|t,v| Float(v) rescue v}
    51:         db.translator.add_translator("float", &prok)
    52:         db.translator.add_translator("real", &prok)
    53:         db.translator.add_translator("double precision", &prok)
    54:
    55:         # Handle blob values with Sequel::SQL::Blob
    56:         db.translator.add_translator("blob"){|t,v| ::Sequel::SQL::Blob.new(v)}
    57:
    58:         db
    59:       end

dataset(opts = nil)

Return instance of Sequel::SQLite::Dataset with the given options.

[Source]

        # File lib/sequel/adapters/sqlite.rb, line 62
    62:       def dataset(opts = nil)
    63:         SQLite::Dataset.new(self, opts)
    64:       end

execute(sql, opts={}, &block)

Run the given SQL with the given arguments and yield each row.

[Source]

        # File lib/sequel/adapters/sqlite.rb, line 77
    77:       def execute(sql, opts={}, &block)
    78:         _execute(sql, opts){|conn| conn.query(sql, opts[:arguments], &block)}
    79:       end

execute_dui(sql, opts={})

Run the given SQL with the given arguments and return the number of changed rows.

[Source]

        # File lib/sequel/adapters/sqlite.rb, line 67
    67:       def execute_dui(sql, opts={})
    68:         _execute(sql, opts){|conn| conn.execute_batch(sql, opts[:arguments]); conn.changes}
    69:       end

execute_insert(sql, opts={})

Run the given SQL with the given arguments and return the last inserted row id.

[Source]

        # File lib/sequel/adapters/sqlite.rb, line 72
    72:       def execute_insert(sql, opts={})
    73:         _execute(sql, opts){|conn| conn.execute(sql, opts[:arguments]); conn.last_insert_row_id}
    74:       end

single_value(sql, opts={})

Run the given SQL with the given arguments and return the first value of the first row.

[Source]

        # File lib/sequel/adapters/sqlite.rb, line 82
    82:       def single_value(sql, opts={})
    83:         _execute(sql, opts){|conn| conn.get_first_value(sql, opts[:arguments])}
    84:       end

[Validate]