Module: OrientSupport::Support

Included in:
ActiveOrient::OrientDB, Array, OrientQuery
Defined in:
lib/support.rb

Instance Method Summary collapse

Instance Method Details

#compose_where(*arg) ⇒ Object

supports

where: ‘string’ where: { property: ‘value’, property: value, … } where: [‘string, { property: value, … }, … ]

Used by update and select



126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/support.rb', line 126

def compose_where *arg
  arg=arg.flatten
  return "" if arg.blank? || arg.size == 1 && arg.first.blank?
 "where " + arg.map do |issue|
   case issue
   when String
    issue
   when Hash
   generate_sql_list issue
  end
 end.join( ' and ' )
end

#generate_sql_list(attributes = {}) ⇒ Object



138
139
140
141
142
143
144
145
146
147
# File 'lib/support.rb', line 138

def generate_sql_list attributes={}
  attributes.map do | key, value |
  case value
  when Numeric
    key.to_s << " = " << value.to_s 
  else #  String, Symbol, Date, Time, Trueclass, Falseclass ...
    key.to_s << ' = ' << "\'#{ value }\'"
  end
  end.join( ' and ' )
end