module Sequelizer
Include this module in any class where you'd like to quickly establish a Sequel
connection to a database.
Constants
- VERSION
Version for the gem
Public Class Methods
options()
click to toggle source
# File lib/sequelizer.rb, line 10 def self.options Options.new.to_hash end
Public Instance Methods
db(options = {})
click to toggle source
Instantiates and memoizes a database connection. The db
method instantiates the connection on the first call and then memoizes itself so only a single connection is used on repeated calls
- options
-
an optional set of database connection options. If no options are provided, options are read from config/sequelizer.yml or from .env or from environment variables.
# File lib/sequelizer.rb, line 21 def db(options = {}) @_sequelizer_db ||= new_db(options) end
find_cached(options)
click to toggle source
# File lib/sequelizer.rb, line 36 def find_cached(options) @cache ||= {} @cache[options] end
new_db(options = {})
click to toggle source
Instantiates and returns a new database connection on each call.
- options
-
an optional set of database connection options. If no options are provided, options are read from config/sequelizer.yml or from .env or from environment variables.
# File lib/sequelizer.rb, line 30 def new_db(options = {}) cached = find_cached(options) return cached if cached && !options[:force_new] @cache[options] = ConnectionMaker.new(options).connection end