Class: Linkage::ResultSets::Database

Inherits:
Linkage::ResultSet show all
Includes:
Helpers::Database
Defined in:
lib/linkage/result_sets/database.rb

Overview

ResultSets::Database is the ResultSet for writing to database tables. You can use it by either referencing it directly like so:

result_set = Linkage::ResultSets::Database.new(connection_options, options)

Or by using ResultSet.[]:

result_set = Linkage::ResultSet['database'].new(connection_options, options)

You can setup a database connection in a few different ways. By default, a SQLite database with the filename of results.db will be created in the current working directory. If you want something different, you can either specify a Sequel-style URI, provide connection options for Sequel.connect, or you can just specify a Sequel::Database object to use.

There are a couple of non-Sequel connection options:

  • :filename - specify filename to use for a SQLite database
  • :dir - specify the parent directory for a SQLite database

This result set creates a database-backed score set and a database-backed match set with their default table names (scores and matches respectively. If either table already exists, an ExistsError will be raised unless you set the :overwrite option to a truthy value in the second options hash.

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :filename => 'results.db'
}

Instance Method Summary collapse

Methods included from Helpers::Database

#database_connection

Methods inherited from Linkage::ResultSet

klass_for, register

Constructor Details

#initialize(connection_options = {}, options = {}) ⇒ Database

Returns a new instance of Database.



44
45
46
47
# File 'lib/linkage/result_sets/database.rb', line 44

def initialize(connection_options = {}, options = {})
  @database = database_connection(connection_options, DEFAULT_OPTIONS)
  @options = options
end

Instance Method Details

#match_setObject



53
54
55
# File 'lib/linkage/result_sets/database.rb', line 53

def match_set
  @match_set ||= MatchSet['database'].new(@database, @options)
end

#score_setObject



49
50
51
# File 'lib/linkage/result_sets/database.rb', line 49

def score_set
  @score_set ||= ScoreSet['database'].new(@database, @options)
end