| Module | Sequel::SQLite::DatabaseMethods |
| In: |
lib/sequel/adapters/shared/sqlite.rb
|
| 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 |
Run all alter_table commands in a transaction. This is technically only needed for drop column.
# File lib/sequel/adapters/shared/sqlite.rb, line 14
14: def alter_table(name, generator=nil, &block)
15: transaction{super}
16: end
A symbol signifying the value of the auto_vacuum PRAGMA.
# File lib/sequel/adapters/shared/sqlite.rb, line 19
19: def auto_vacuum
20: AUTO_VACUUM[pragma_get(:auto_vacuum).to_i]
21: end
Set the auto_vacuum PRAGMA using the given symbol (:none, :full, or :incremental).
# 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
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.
# 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
Get the value of the given PRAGMA.
# File lib/sequel/adapters/shared/sqlite.rb, line 59
59: def pragma_get(name)
60: self["PRAGMA #{name}"].single_value
61: end
Set the value of the given PRAGMA to value.
# File lib/sequel/adapters/shared/sqlite.rb, line 64
64: def pragma_set(name, value)
65: execute_ddl("PRAGMA #{name} = #{value}")
66: end
A symbol signifying the value of the synchronous PRAGMA.
# File lib/sequel/adapters/shared/sqlite.rb, line 69
69: def synchronous
70: SYNCHRONOUS[pragma_get(:synchronous).to_i]
71: end
Set the synchronous PRAGMA using the given symbol (:off, :normal, or :full).
# File lib/sequel/adapters/shared/sqlite.rb, line 74
74: def synchronous=(value)
75: value = SYNCHRONOUS.index(value) || (raise Error, "Invalid value for synchronous option. Please specify one of :off, :normal, :full.")
76: pragma_set(:synchronous, value)
77: end
Array of symbols specifying the table names in the current database.
Options:
# File lib/sequel/adapters/shared/sqlite.rb, line 83
83: def tables(opts={})
84: m = output_identifier_meth
85: metadata_dataset.from(:sqlite_master).server(opts[:server]).filter(TABLES_FILTER).map{|r| m.call(r[:name])}
86: end
A symbol signifying the value of the temp_store PRAGMA.
# File lib/sequel/adapters/shared/sqlite.rb, line 89
89: def temp_store
90: TEMP_STORE[pragma_get(:temp_store).to_i]
91: end
Set the temp_store PRAGMA using the given symbol (:default, :file, or :memory).
# File lib/sequel/adapters/shared/sqlite.rb, line 94
94: def temp_store=(value)
95: value = TEMP_STORE.index(value) || (raise Error, "Invalid value for temp_store option. Please specify one of :default, :file, :memory.")
96: pragma_set(:temp_store, value)
97: end