class MiGA::SQLite

SQLite3 wrapper for MiGA.

Attributes

opts[R]

Options hash

path[R]

Database absolute path

Public Class Methods

default_opts(opts = {}) click to toggle source

Default parsing options. Supported opts keys:

  • :busy_attempts: Number of times to retry when database is busy (default: 3)

# File lib/miga/sqlite.rb, line 14
def default_opts(opts = {})
  opts[:busy_attempts] ||= 3
  opts
end
new(path, opts = {}) click to toggle source

Create MiGA::SQLite with database in path (without opening a connection) and options opts (see .default_opts)

# File lib/miga/sqlite.rb, line 31
def initialize(path, opts = {})
  @opts = MiGA::SQLite.default_opts(opts)
  @path = File.absolute_path(path)
end

Public Instance Methods

run(*cmd) click to toggle source

Executes cmd and returns the result

# File lib/miga/sqlite.rb, line 38
def run(*cmd)
  busy_attempts ||= 0
  conn = SQLite3::Database.new(path)
  conn.execute(*cmd)
rescue SQLite3::BusyException => e
  busy_attempts += 1
  raise "Database busy #{path}: #{e.message}" if busy_attempts >= 3

  sleep(1)
  retry
end