Module: Sequel::SQLite::DatabaseMethods

Module | Sequel::SQLite::DatabaseMethods
In: | lib/sequel/adapters/shared/sqlite.rb

### Methods

alter_table auto_vacuum auto_vacuum= database_type indexes pragma_get pragma_set supports_savepoints? synchronous synchronous= tables temp_store temp_store=

### Constants

AUTO_VACUUM | = | [:none, :full, :incremental].freeze
PRIMARY_KEY_INDEX_RE | = | /\Asqlite_autoindex_/.freeze
SYNCHRONOUS | = | [:off, :normal, :full].freeze
TABLES_FILTER | = | "type = 'table' AND NOT name = 'sqlite_sequence'"
TEMP_STORE | = | [:default, :file, :memory].freeze

### Public Instance methods

alter_table(name, generator=nil, &block)

Run all alter_table commands in a transaction. This is technically only needed for drop column.

[Source]

        # File lib/sequel/adapters/shared/sqlite.rb, line 12
    12:       def alter_table(name, generator=nil, &block)
    13:         remove_cached_schema(name)
    14:         generator ||= Schema::AlterTableGenerator.new(self, &block)
    15:         transaction{generator.operations.each{|op| alter_table_sql_list(name, [op]).flatten.each{|sql| execute_ddl(sql)}}}
    16:       end

auto_vacuum()

A symbol signifying the value of the auto_vacuum PRAGMA.

[Source]

        # File lib/sequel/adapters/shared/sqlite.rb, line 19
    19:       def auto_vacuum
    20:         AUTO_VACUUM[pragma_get(:auto_vacuum).to_i]
    21:       end

auto_vacuum=(value)

Set the auto_vacuum PRAGMA using the given symbol (:none, :full, or :incremental).

[Source]

        # File lib/sequel/adapters/shared/sqlite.rb, line 25
    25:       def auto_vacuum=(value)
    26:         value = AUTO_VACUUM.index(value) || (raise Error, "Invalid value for auto_vacuum option. Please specify one of :none, :full, :incremental.")
    27:         pragma_set(:auto_vacuum, value)
    28:       end

database_type()

SQLite uses the :sqlite database type.

[Source]

        # File lib/sequel/adapters/shared/sqlite.rb, line 31
    31:       def database_type
    32:         :sqlite
    33:       end

indexes(table)

Return a hash containing index information. Hash keys are index name symbols. Values are subhashes with two keys, :columns and :unique. The value of :columns is an array of symbols of column names. The value of :unique is true or false depending on if the index is unique.

[Source]

        # File lib/sequel/adapters/shared/sqlite.rb, line 39
    39:       def indexes(table)
    40:         m = output_identifier_meth
    41:         im = input_identifier_meth
    42:         indexes = {}
    43:         begin
    44:           metadata_dataset.with_sql("PRAGMA index_list(?)", im.call(table)).each do |r|
    45:             next if r[:name] =~ PRIMARY_KEY_INDEX_RE
    46:             indexes[m.call(r[:name])] = {:unique=>r[:unique].to_i==1}
    47:           end
    48:         rescue Sequel::DatabaseError
    49:           nil
    50:         else
    51:           indexes.each do |k, v|
    52:             v[:columns] = metadata_dataset.with_sql("PRAGMA index_info(?)", im.call(k)).map(:name).map{|x| m.call(x)}
    53:           end
    54:         end
    55:         indexes
    56:       end

pragma_get(name)

Get the value of the given PRAGMA.

[Source]

        # File lib/sequel/adapters/shared/sqlite.rb, line 59
    59:       def pragma_get(name)
    60:         self["PRAGMA #{name}"].single_value
    61:       end

pragma_set(name, value)

Set the value of the given PRAGMA to value.

[Source]

        # File lib/sequel/adapters/shared/sqlite.rb, line 64
    64:       def pragma_set(name, value)
    65:         execute_ddl("PRAGMA #{name} = #{value}")
    66:       end

supports_savepoints?()

SQLite supports savepoints

[Source]

        # File lib/sequel/adapters/shared/sqlite.rb, line 69
    69:       def supports_savepoints?
    70:         true
    71:       end

synchronous()

A symbol signifying the value of the synchronous PRAGMA.

[Source]

        # File lib/sequel/adapters/shared/sqlite.rb, line 74
    74:       def synchronous
    75:         SYNCHRONOUS[pragma_get(:synchronous).to_i]
    76:       end

synchronous=(value)

Set the synchronous PRAGMA using the given symbol (:off, :normal, or :full).

[Source]

        # File lib/sequel/adapters/shared/sqlite.rb, line 79
    79:       def synchronous=(value)
    80:         value = SYNCHRONOUS.index(value) || (raise Error, "Invalid value for synchronous option. Please specify one of :off, :normal, :full.")
    81:         pragma_set(:synchronous, value)
    82:       end

tables(opts={})

Array of symbols specifying the table names in the current database.

Options:

- :server - Set the server to use.

[Source]

        # File lib/sequel/adapters/shared/sqlite.rb, line 88
    88:       def tables(opts={})
    89:         m = output_identifier_meth
    90:         metadata_dataset.from(:sqlite_master).server(opts[:server]).filter(TABLES_FILTER).map{|r| m.call(r[:name])}
    91:       end

temp_store()

A symbol signifying the value of the temp_store PRAGMA.

[Source]

        # File lib/sequel/adapters/shared/sqlite.rb, line 94
    94:       def temp_store
    95:         TEMP_STORE[pragma_get(:temp_store).to_i]
    96:       end

temp_store=(value)

Set the temp_store PRAGMA using the given symbol (:default, :file, or :memory).

[Source]

         # File lib/sequel/adapters/shared/sqlite.rb, line 99
     99:       def temp_store=(value)
    100:         value = TEMP_STORE.index(value) || (raise Error, "Invalid value for temp_store option. Please specify one of :default, :file, :memory.")
    101:         pragma_set(:temp_store, value)
    102:       end

[Validate]