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
72 73 74 75 76 77 78 |
# File 'lib/rom/yesql/gateway.rb', line 72 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)
44 45 46 |
# File 'lib/rom/yesql/gateway.rb', line 44 def connection @connection end |
#path ⇒ String (readonly)
Returns a path to files with SQL queries.
27 |
# File 'lib/rom/yesql/gateway.rb', line 27 option :path, reader: true, optional: true |
#queries ⇒ Hash (readonly)
Returns a hash with queries.
31 |
# File 'lib/rom/yesql/gateway.rb', line 31 option :queries, default: -> { EMPTY_HASH } |
#query_proc ⇒ Proc (readonly)
This defaults to simple interpolation of the query using option hash passed to a relation
36 37 38 39 40 |
# File 'lib/rom/yesql/gateway.rb', line 36 option :query_proc, reader: true, default: proc { |_gateway| proc do |_name, query, opts| query % opts end } |
#uri ⇒ String (readonly)
Returns connection string.
23 |
# File 'lib/rom/yesql/gateway.rb', line 23 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
87 88 89 |
# File 'lib/rom/yesql/gateway.rb', line 87 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
98 99 100 |
# File 'lib/rom/yesql/gateway.rb', line 98 def dataset?(_name) ! @dataset.nil? end |