Class: Arel::Visitors::Datastore

Inherits:
ToSql
  • Object
show all
Defined in:
lib/arel/visitors/datastore.rb

Defined Under Namespace

Classes: QString

Instance Method Summary collapse

Instance Method Details

#get_limit_and_offset(o) ⇒ Object



116
117
118
119
120
121
# File 'lib/arel/visitors/datastore.rb', line 116

def get_limit_and_offset( o )
  options = {}
  options[:limit]  = o.limit.expr if o.limit
  options[:offset] = o.offset.expr if o.offset
  options
end

#insert_type_case(value) ⇒ Object



128
129
130
# File 'lib/arel/visitors/datastore.rb', line 128

def insert_type_case( value )
  value.is_a?( ActiveSupport::TimeWithZone ) ? value.time : value
end

#visit_Arel_Nodes_DeleteStatement(o) ⇒ Object



142
143
144
# File 'lib/arel/visitors/datastore.rb', line 142

def visit_Arel_Nodes_DeleteStatement o
  QString.new( @connection, o.relation.name ).wheres( o.wheres )
end

#visit_Arel_Nodes_InsertStatement(o) ⇒ Object



132
133
134
135
136
# File 'lib/arel/visitors/datastore.rb', line 132

def visit_Arel_Nodes_InsertStatement o
  e = AppEngine::Datastore::Entity.new(o.relation.name)
  o.columns.each_with_index{|c,i| e[c.name] = insert_type_case(o.values.left[i]) }
  e
end

#visit_Arel_Nodes_SelectStatement(o) ⇒ Object



123
124
125
126
# File 'lib/arel/visitors/datastore.rb', line 123

def visit_Arel_Nodes_SelectStatement o
  c    = o.cores.first
  QString.new( @connection, c.froms.name, get_limit_and_offset(o) ).wheres( c.wheres ).orders(o.orders).projections( c.projections )
end

#visit_Arel_Nodes_UpdateStatement(o) ⇒ Object



138
139
140
# File 'lib/arel/visitors/datastore.rb', line 138

def visit_Arel_Nodes_UpdateStatement o
  QString.new( @connection, o.relation.name, :values => o.values.collect{|v| [ v.left.name, insert_type_case(v.right) ] } ).wheres( o.wheres )
end