Class: ROM::Yesql::Gateway
- Inherits:
-
Gateway
- Object
- Gateway
- ROM::Yesql::Gateway
- Extended by:
- Initializer
- Defined in:
- lib/rom/yesql/gateway.rb
Overview
Yesql gateway exposes access to configured SQL queries
Relations created with datasets provided by this gateway automatically expose access to gateway’s queries.
Instance Attribute Summary collapse
- #connection ⇒ Object readonly
-
#path ⇒ String
readonly
A path to files with SQL queries.
-
#queries ⇒ Hash
readonly
A hash with queries.
-
#query_proc ⇒ Proc
readonly
This defaults to simple interpolation of the query using option hash passed to a relation.
-
#uri ⇒ String
readonly
Connection string.
Instance Method Summary collapse
-
#dataset(_name) ⇒ Dataset
private
Initializes a dataset.
-
#dataset?(_name) ⇒ True
private
Returns if a dataset with the given name exists.
-
#initialize ⇒ Gateway
constructor
Initializes a yesql gateway.
Constructor Details
#initialize ⇒ Gateway
Initializes a yesql gateway
74 75 76 77 78 79 80 |
# File 'lib/rom/yesql/gateway.rb', line 74 def initialize(*) super @connection = Sequel.connect(uri, ) @queries = @queries.merge(load_queries(path)).freeze Relation.query_proc(query_proc) Relation.load_queries(queries) end |
Instance Attribute Details
#connection ⇒ Object (readonly)
46 47 48 |
# File 'lib/rom/yesql/gateway.rb', line 46 def connection @connection end |
#path ⇒ String (readonly)
Returns a path to files with SQL queries.
29 |
# File 'lib/rom/yesql/gateway.rb', line 29 option :path, reader: true, optional: true |
#queries ⇒ Hash (readonly)
Returns a hash with queries.
33 |
# File 'lib/rom/yesql/gateway.rb', line 33 option :queries, default: -> { EMPTY_HASH } |
#query_proc ⇒ Proc (readonly)
This defaults to simple interpolation of the query using option hash passed to a relation
38 39 40 41 42 |
# File 'lib/rom/yesql/gateway.rb', line 38 option :query_proc, reader: true, default: proc { |_gateway| proc do |_name, query, opts| query % opts end } |
#uri ⇒ String (readonly)
Returns connection string.
25 |
# File 'lib/rom/yesql/gateway.rb', line 25 param :uri |
Instance Method Details
#dataset(_name) ⇒ Dataset
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes a dataset
Since all relations use the same dataset we simply create one instance
89 90 91 |
# File 'lib/rom/yesql/gateway.rb', line 89 def dataset(_name) @dataset ||= Dataset.new(connection) end |
#dataset?(_name) ⇒ True
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns if a dataset with the given name exists
This always returns true because all relations use the same dataset
100 101 102 |
# File 'lib/rom/yesql/gateway.rb', line 100 def dataset?(_name) !@dataset.nil? end |