Class: Squongo::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/squongo/connection.rb

Constant Summary collapse

WAL_QUERY =
'PRAGMA journal_mode=WAL;'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Connection

Returns a new instance of Connection.



10
11
12
13
14
# File 'lib/squongo/connection.rb', line 10

def initialize(path)
  @path = path
  @db = SQLite3::Database.open(path)
  ensure_mode
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



8
9
10
# File 'lib/squongo/connection.rb', line 8

def db
  @db
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/squongo/connection.rb', line 8

def path
  @path
end

Class Method Details

.connect(path) ⇒ Object



20
21
22
# File 'lib/squongo/connection.rb', line 20

def self.connect(path)
  self.new(path)
end

Instance Method Details

#ensure_modeObject



24
25
26
27
# File 'lib/squongo/connection.rb', line 24

def ensure_mode
  return unless first_connection
  wal_mode
end

#first_connectionObject



33
34
35
# File 'lib/squongo/connection.rb', line 33

def first_connection
  !(File.exist?(path))
end

#reconnectObject



16
17
18
# File 'lib/squongo/connection.rb', line 16

def reconnect
  @db = SQLite3::Database.open(path)
end

#wal_modeObject



29
30
31
# File 'lib/squongo/connection.rb', line 29

def wal_mode
  @db.execute WAL_QUERY
end