Module: MirrorDb

Defined in:
lib/webget/mirror/database/open.rb,
lib/webget/mirror/database/models.rb,
lib/webget/mirror/database/schema.rb

Defined Under Namespace

Modules: Model Classes: CreateDb

Class Method Summary collapse

Class Method Details

.open(path = './mirror.db') ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/webget/mirror/database/open.rb', line 4

def self.open( path='./mirror.db' )

  ### reuse connect here !!!
  ###   why? why not?

  config = {
      adapter:  'sqlite3',
      database: path,
  }

  ActiveRecord::Base.establish_connection( config )
  # ActiveRecord::Base.logger = Logger.new( STDOUT )

    ## try to speed up sqlite
    ##   see http://www.sqlite.org/pragma.html
    con = ActiveRecord::Base.connection
    con.execute( 'PRAGMA synchronous=OFF;' )
    con.execute( 'PRAGMA journal_mode=OFF;' )
    con.execute( 'PRAGMA temp_store=MEMORY;' )

  ##########################
  ### auto_migrate
  unless Model::Page.table_exists?
      CreateDb.new.up
  end
end