-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addresses #52 Profile full monthly generation
- Experiment with removing one-by-one rights retrieval in favor of Sequel batch query for multiple htids.
- Loading branch information
Showing
20 changed files
with
162 additions
and
412 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# frozen_string_literal: true | ||
|
||
require "dotenv" | ||
Dotenv.load(".env") | ||
|
||
require "delegate" | ||
require "mysql2" | ||
require "sequel" | ||
|
||
# Backend for connection to MySQL database for production information about | ||
# rights | ||
class Database < SimpleDelegator | ||
attr_reader :rawdb | ||
attr_accessor :connection_string | ||
|
||
def initialize(connection_string = ENV["DB_CONNECTION_STRING"], **) | ||
@rawdb = self.class.connection(connection_string, **) | ||
super(@rawdb) | ||
end | ||
|
||
# #connection will take | ||
# * a full connection string (passed here OR in the environment | ||
# variable MYSQL_CONNECTION_STRING) | ||
# * a set of named arguments, drawn from those passed in and the | ||
# environment. Arguments are those supported by Sequel. | ||
# | ||
# Environment variables are mapped as follows: | ||
# | ||
# user: DB_USER | ||
# password: DB_PASSWORD | ||
# host: DB_HOST | ||
# port: DB_PORT | ||
# database: DB_DATABASE | ||
# adapter: DB_ADAPTER | ||
def self.connection(connection_string = ENV["DB_CONNECTION_STRING"], | ||
**kwargs) | ||
|
||
if connection_string.nil? | ||
db_args = gather_db_args(kwargs).merge( | ||
config_local_infile: true | ||
) | ||
Sequel.connect(**db_args, logger: Logger.new($stdout, level: Logger::WARN)) | ||
else | ||
Sequel.connect(connection_string, logger: Logger.new($stdout, level: Logger::WARN)) | ||
end | ||
end | ||
|
||
class << self | ||
private | ||
|
||
def gather_db_args(args) | ||
%i[user password host | ||
port database adapter].each do |db_arg| | ||
args[db_arg] ||= ENV["DB_#{db_arg.to_s.upcase}"] | ||
end | ||
|
||
args[:host] ||= "localhost" | ||
args[:adapter] ||= :mysql2 | ||
args[:database] ||= "ht_rights" | ||
args | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.