Module: Hecks::Ports::Query
- Defined in:
- lib/hecks/ports/query.rb,
lib/hecks/ports/query/ordering.rb,
lib/hecks/ports/query/in_memory.rb
Overview
Common query execution boundary. Adapters expose one optional native hook; all other query behavior remains in the shared interpreter. Ordering (the meaning of an ask's answer order) and InMemory (the fallback engine for stores with no query engine of their own) are its collaborators — query/ordering.rb and query/in_memory.rb.
Defined Under Namespace
Modules: InMemory, Ordering Classes: Unsupported
Class Method Summary collapse
- .execute(repository, specification, args = {}, context: {}) ⇒ Object
- .validate!(specification, adapter) ⇒ Object
Class Method Details
.execute(repository, specification, args = {}, context: {}) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/hecks/ports/query.rb', line 13 def execute(repository, specification, args = {}, context: {}) adapter = repository.respond_to?(:adapter) ? repository.adapter : repository return nil unless adapter.respond_to?(:query) validate!(specification, adapter) adapter.query(specification, args, context: context) end |
.validate!(specification, adapter) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/hecks/ports/query.rb', line 21 def validate!(specification, adapter) if specification.cursor && specification.offset raise Unsupported, "a query cannot combine cursor and offset pagination" end return if specification.inspection.nil? || adapter.respond_to?(:inspect_query) return if specification.inspection.mode.to_s == "sql" && adapter.respond_to?(:query) raise Unsupported, "#{adapter.class} cannot inspect generated queries" end |