-
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.
Browse files
Browse the repository at this point in the history
* Addresses #52 Profile full monthly generation - Experiment with removing one-by-one rights retrieval in favor of Sequel batch query for multiple htids. - Add `HathifileWriter` class with limit on number of HTIDs in batch rights query - Use Ettin Settings for DB connection string instead of `ENV` directly - Connect to `ht` instead of `ht_rights` so `ht.ht_collections` can be read - Add `mariadb-client` to both dockerfiles - Update to `hathifiles_database` 0.3.0
- Loading branch information
Showing
24 changed files
with
232 additions
and
473 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 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,62 @@ | ||
# frozen_string_literal: true | ||
|
||
require "dotenv" | ||
Dotenv.load(".env") | ||
|
||
require "delegate" | ||
require "mysql2" | ||
require "sequel" | ||
require "settings" | ||
|
||
# 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 = Settings.database.url, **) | ||
@rawdb = self.class.connection(connection_string, **) | ||
super(@rawdb) | ||
end | ||
|
||
# #connection will take | ||
# * a full connection string (passed here OR in Settings which is generally 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 = Settings.database.url, **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" | ||
args | ||
end | ||
end | ||
end |
Oops, something went wrong.