Module: MiddleSquid::Database
Constant Summary collapse
- @@db =
nil
Class Method Summary collapse
-
.setup(path) ⇒ Object
Setup the database.
Instance Method Summary collapse
Class Method Details
.setup(path) ⇒ Object
Setup the database. Use Builder#database instead.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/middle_squid/database.rb', line 7 def self.setup(path) @@db.close if @@db @@db = SQLite3::Database.new path @@db.execute <<-SQL CREATE TABLE IF NOT EXISTS domains ( category TEXT, host TEXT ) SQL @@db.execute <<-SQL CREATE UNIQUE INDEX IF NOT EXISTS unique_domains ON domains ( category, host ) SQL @@db.execute <<-SQL CREATE TABLE IF NOT EXISTS urls ( category TEXT, host TEXT, path TEXT ) SQL @@db.execute <<-SQL CREATE UNIQUE INDEX IF NOT EXISTS unique_urls ON urls ( category, host, path ) SQL # minimize downtime due to locks when the database is rebuilding # see http://www.sqlite.org/wal.html @@db.execute 'PRAGMA journal_mode=WAL' end |
Instance Method Details
#db ⇒ SQLite3::Database
42 43 44 45 46 |
# File 'lib/middle_squid/database.rb', line 42 def db raise "The database is not initialized. Did you call Builder#database in your configuration file?" unless @@db @@db end |