Module | Sequel::SQLite::DatabaseMethods |
In: |
lib/sequel_core/adapters/shared/sqlite.rb
|
AUTO_VACUUM | = | {'0' => :none, '1' => :full, '2' => :incremental}.freeze |
SYNCHRONOUS | = | {'0' => :off, '1' => :normal, '2' => :full}.freeze |
TABLES_FILTER | = | "type = 'table' AND NOT name = 'sqlite_sequence'" |
TEMP_STORE | = | {'0' => :default, '1' => :file, '2' => :memory}.freeze |
TYPES | = | Sequel::Schema::SQL::TYPES.merge(Bignum=>'integer') |
Run all alter_table commands in a transaction. This is technically only needed for drop column.
# File lib/sequel_core/adapters/shared/sqlite.rb, line 12 12: def alter_table(name, generator=nil, &block) 13: transaction{super} 14: end
SQLite supports limited table modification. You can add a column or an index. Dropping columns is supported by copying the table into a temporary table, dropping the table, and creating a new table without the column inside of a transaction.
# File lib/sequel_core/adapters/shared/sqlite.rb, line 20 20: def alter_table_sql(table, op) 21: case op[:op] 22: when :add_column, :add_index, :drop_index 23: super 24: when :drop_column 25: columns_str = (schema_parse_table(table, {}).map{|c| c[0]} - Array(op[:name])).join(",") 26: defined_columns_str = column_list_sql parse_pragma(table, {}).reject{ |c| c[:name] == op[:name].to_s} 27: ["CREATE TEMPORARY TABLE #{table}_backup(#{defined_columns_str})", 28: "INSERT INTO #{table}_backup SELECT #{columns_str} FROM #{table}", 29: "DROP TABLE #{table}", 30: "CREATE TABLE #{table}(#{defined_columns_str})", 31: "INSERT INTO #{table} SELECT #{columns_str} FROM #{table}_backup", 32: "DROP TABLE #{table}_backup"] 33: else 34: raise Error, "Unsupported ALTER TABLE operation" 35: end 36: end
A symbol signifying the value of the auto_vacuum PRAGMA.
# File lib/sequel_core/adapters/shared/sqlite.rb, line 39 39: def auto_vacuum 40: AUTO_VACUUM[pragma_get(:auto_vacuum).to_s] 41: end
Set the auto_vacuum PRAGMA using the given symbol (:none, :full, or :incremental).
# File lib/sequel_core/adapters/shared/sqlite.rb, line 45 45: def auto_vacuum=(value) 46: value = AUTO_VACUUM.key(value) || (raise Error, "Invalid value for auto_vacuum option. Please specify one of :none, :full, :incremental.") 47: pragma_set(:auto_vacuum, value) 48: end
Get the value of the given PRAGMA.
# File lib/sequel_core/adapters/shared/sqlite.rb, line 51 51: def pragma_get(name) 52: self["PRAGMA #{name}"].single_value 53: end
Set the value of the given PRAGMA to value.
# File lib/sequel_core/adapters/shared/sqlite.rb, line 56 56: def pragma_set(name, value) 57: execute_ddl("PRAGMA #{name} = #{value}") 58: end
A symbol signifying the value of the synchronous PRAGMA.
# File lib/sequel_core/adapters/shared/sqlite.rb, line 61 61: def synchronous 62: SYNCHRONOUS[pragma_get(:synchronous).to_s] 63: end
Set the synchronous PRAGMA using the given symbol (:off, :normal, or :full).
# File lib/sequel_core/adapters/shared/sqlite.rb, line 66 66: def synchronous=(value) 67: value = SYNCHRONOUS.key(value) || (raise Error, "Invalid value for synchronous option. Please specify one of :off, :normal, :full.") 68: pragma_set(:synchronous, value) 69: end
Array of symbols specifying the table names in the current database.
Options:
# File lib/sequel_core/adapters/shared/sqlite.rb, line 75 75: def tables(opts={}) 76: ds = self[:sqlite_master].server(opts[:server]).filter(TABLES_FILTER) 77: ds.identifier_output_method = nil 78: ds.identifier_input_method = nil 79: ds2 = dataset 80: ds.map{|r| ds2.send(:output_identifier, r[:name])} 81: end
A symbol signifying the value of the temp_store PRAGMA.
# File lib/sequel_core/adapters/shared/sqlite.rb, line 84 84: def temp_store 85: TEMP_STORE[pragma_get(:temp_store).to_s] 86: end
Set the temp_store PRAGMA using the given symbol (:default, :file, or :memory).
# File lib/sequel_core/adapters/shared/sqlite.rb, line 89 89: def temp_store=(value) 90: value = TEMP_STORE.key(value) || (raise Error, "Invalid value for temp_store option. Please specify one of :default, :file, :memory.") 91: pragma_set(:temp_store, value) 92: end