Class: Diametric::Query

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/diametric/query.rb

Overview

Query objects are used to generate Datomic queries, whether to send via an external client or via the persistence API. The two methods used to generate a query are .where and .filter, both of which are chainable. To get the query data and arguments for a Query, use the data method.

If you are using a persistence API, you can ask Query to get the results of a Datomic query. Diametric::Query is an Enumerable. To get the results of a query, use Enumerable methods such as .each or .first. Query also provides a .all method to run the query and get the results.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, connection_or_database = nil, resolve = false) ⇒ Query

Create a new Datomic query.

Parameters:

  • model (Entity)

    This model must include Datomic::Entity. Including a persistence module is optional.


25
26
27
28
29
30
31
32
33
# File 'lib/diametric/query.rb', line 25

def initialize(model, connection_or_database=nil, resolve=false)
  @model = model
  @conditions = {}
  @filters = []
  @filter_attrs = []
  @filter_values = []
  @conn_or_db = connection_or_database
  @resolve = resolve
end

Instance Attribute Details

#conditionsObject

Returns the value of attribute conditions


19
20
21
# File 'lib/diametric/query.rb', line 19

def conditions
  @conditions
end

#connectionObject (readonly)

Returns the value of attribute connection


19
20
21
# File 'lib/diametric/query.rb', line 19

def connection
  @connection
end

#filter_attrsObject

Returns the value of attribute filter_attrs


19
20
21
# File 'lib/diametric/query.rb', line 19

def filter_attrs
  @filter_attrs
end

#filter_valuesObject

Returns the value of attribute filter_values


19
20
21
# File 'lib/diametric/query.rb', line 19

def filter_values
  @filter_values
end

#filtersObject

Returns the value of attribute filters


19
20
21
# File 'lib/diametric/query.rb', line 19

def filters
  @filters
end

#modelObject (readonly)

Returns the value of attribute model


19
20
21
# File 'lib/diametric/query.rb', line 19

def model
  @model
end

#resolveObject (readonly)

Returns the value of attribute resolve


19
20
21
# File 'lib/diametric/query.rb', line 19

def resolve
  @resolve
end

Instance Method Details

#all(conn_or_db = @conn_or_db) ⇒ Array<Entity>

Return all query results.

Returns: