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 " CREATE TABLE IF NOT EXISTS domains (\n category TEXT, host TEXT\n )\n SQL\n\n @@db.execute <<-SQL\n CREATE UNIQUE INDEX IF NOT EXISTS unique_domains ON domains (\n category, host\n )\n SQL\n\n @@db.execute <<-SQL\n CREATE TABLE IF NOT EXISTS urls (\n category TEXT, host TEXT, path TEXT\n )\n SQL\n\n @@db.execute <<-SQL\n CREATE UNIQUE INDEX IF NOT EXISTS unique_urls ON urls (\n category, host, path\n )\n SQL\n\n # minimize downtime due to locks when the database is rebuilding\n # see http://www.sqlite.org/wal.html\n @@db.execute 'PRAGMA journal_mode=WAL'\nend\n" |
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 |