Class: OrientDB::AR::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/orientdb-ar/sql/query.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, query = OrientDB::SQL::Query.new) ⇒ Query

Returns a new instance of Query.



11
12
13
14
# File 'lib/orientdb-ar/sql/query.rb', line 11

def initialize(model, query = OrientDB::SQL::Query.new)
  @model, @query = model, query
  @query.from model.oclass_name
end

Instance Attribute Details

#modelObject

Returns the value of attribute model.



3
4
5
# File 'lib/orientdb-ar/sql/query.rb', line 3

def model
  @model
end

#queryObject

Returns the value of attribute query.



3
4
5
# File 'lib/orientdb-ar/sql/query.rb', line 3

def query
  @query
end

Class Method Details

.for_oclass(name, query = OrientDB::SQL::Query.new) ⇒ Object



5
6
7
8
9
# File 'lib/orientdb-ar/sql/query.rb', line 5

def self.for_oclass(name, query = OrientDB::SQL::Query.new)
  obj = new OrientDB::AR::Base, query
  obj.from OrientDB::AR::Base.oclass_name_for name
  obj
end

Instance Method Details

#allObject



23
24
25
# File 'lib/orientdb-ar/sql/query.rb', line 23

def all
  model.connection.all(query).map { |doc| doc.to_orientdb_ar }
end

#deleteObject



43
44
45
# File 'lib/orientdb-ar/sql/query.rb', line 43

def delete
  OrientDB::AR::Delete.from_query(self).run
end

#firstObject



27
28
29
# File 'lib/orientdb-ar/sql/query.rb', line 27

def first
  model.connection.first(query).to_orientdb_ar
end

#first_resultObject



35
36
37
# File 'lib/orientdb-ar/sql/query.rb', line 35

def first_result
  model.connection.first(query)
end

#inspectObject Also known as: to_s



47
48
49
# File 'lib/orientdb-ar/sql/query.rb', line 47

def inspect
  %{#<OrientDB::AR::Query:#{model.name} query="#{query.to_s}">}
end

#resultsObject



31
32
33
# File 'lib/orientdb-ar/sql/query.rb', line 31

def results
  model.connection.all(query).map
end

#update(*args) ⇒ Object



39
40
41
# File 'lib/orientdb-ar/sql/query.rb', line 39

def update(*args)
  OrientDB::AR::Update.from_query(self, *args).run
end