Class: Marc2LinkedData::CapDb

Inherits:
Object
  • Object
show all
Defined in:
lib/marc2linkeddata/cap_db.rb

Overview

An interface to an SQL database using Sequel

Constant Summary collapse

@@log =
Logger.new('log/cap_db.log')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCapDb

Returns a new instance of CapDb.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/marc2linkeddata/cap_db.rb', line 22

def initialize
  @db_config = {}
  @db_config['host'] = ENV['SUL_CAP_DB_HOST'] || 'localhost'
  @db_config['port'] = ENV['SUL_CAP_DB_PORT'] || '3306'
  @db_config['user'] = ENV['SUL_CAP_DB_USER'] || 'capUser'
  @db_config['password'] = ENV['SUL_CAP_DB_PASSWORD'] || 'capPass'
  @db_config['database'] = ENV['SUL_CAP_DB_DATABASE'] || 'cap'
  options = @db_config.merge(
      {
          :encoding => 'utf8',
          :max_connections => 10,
          :logger => @@log
      })
  @db = Sequel.mysql(options)
  @db.extension(:pagination)
  # Ensure the connection is good on startup, raises exceptions on failure
  puts "#{@db} connected: #{@db.test_connection}"
end

Instance Attribute Details

#dbObject

Returns the value of attribute db.



15
16
17
# File 'lib/marc2linkeddata/cap_db.rb', line 15

def db
  @db
end

#db_configObject

Returns the value of attribute db_config.



16
17
18
# File 'lib/marc2linkeddata/cap_db.rb', line 16

def db_config
  @db_config
end

Class Method Details

.log_model_info(m) ⇒ Object



18
19
20
# File 'lib/marc2linkeddata/cap_db.rb', line 18

def self.log_model_info(m)
  @@log.info "table: #{m.table_name}, columns: #{m.columns}, pk: #{m.primary_key}"
end