Method: ModelClass#get_records
- Defined in:
- lib/model/the_class.rb
#get_records(**args) ⇒ Object Also known as: get_documents
»GetRecords« uses the REST-Interface to query the database. The alternative »QueryDatabase« submits the query via Execute.
Both methods rely on OrientSupport::OrientQuery and its capacity to support complex query-builds. The method requires a hash of arguments. The following keys are supported:
projection:
SQL-Queries use »select« to specify a projection (ie. ‘select sum(a), b+5 as z from class where …`)
In ruby »select« is a method of enumeration. To specify what to »select« from in the query-string we use »projection«, which accepts different arguments
projection: a_string --> inserts the sting as it appears
projection: an OrientSupport::OrientQuery-Object --> performs a sub-query and uses the result for further querying though the given parameters.
projection: [a, b, c] --> "a, b, c" (inserts a comma-separated list)
projection: {a: b, "sum(x)" => f} --> "a as b, sum(x) as f" (renames properties and uses functions)
distinct:
Constructs a query like »select distinct(property) [as property] from …«
distinct: :property --> the result is mapped to the property »distinct«.
distinct: [:property] --> the result replaces the property
distinct: {property: :some_name} --> the result is mapped to ModelInstance.some_name
order:
Sorts the result-set. If new properties were introduced via select:, distinct: etc. Sorting takes place on these properties
order: :property {property: asc, property: desc}[property, property, .. ](orderdirection is 'asc')
Further supported Parameter:
group_by
skip
limit
unwind
see orientdb- documentation (https://orientdb.com/docs/last/SQL-Query.html)
query:
Instead of providing the parameter to »get_records«, a OrientSupport::OrientQuery can build and tested prior to the method-call. The OrientQuery-Object is then provided with the query-parameter. I.e.
q = OrientSupport::OrientQuery.new
ORD.create_class :test_model
q.from TestModel
q.where {name: 'Thomas'}
count = TestModel.count query: q
q.limit 10
0.step(count,10) do |x|
q.skip = x
puts TestModel.get_documents(query: q).map{|x| x.adress }.join('\t')
end
prints a Table with 10 columns.
496 497 498 |
# File 'lib/model/the_class.rb', line 496 def get_records **args db.get_records(from: self, **args){self} end |