Module: OrientSupport::Support
- Included in:
- ActiveOrient::API, ActiveOrient::OrientDB, Array, Hash, MatchStatement, OrientQuery
- Defined in:
- lib/support.rb
Instance Method Summary collapse
-
#compose_where(*arg) ⇒ Object
> “where z=34 and u = 6”.
-
#generate_sql_list(attributes = {}) ⇒ Object
designs a list of “Key = Value” pairs combined by “and” or the fillword provided by the block ORD.generate_sql_list where: 25 , upper: ‘65’ => “where = 25 and upper = ‘65’” ORD.generate_sql_list( con_id: 25 , symbol: :G) { ‘,’ } => “con_id = 25 , symbol = ‘G’”.
Instance Method Details
#compose_where(*arg) ⇒ Object
> “where z=34 and u = 6”
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/support.rb', line 16 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 else generate_sql_list issue end end.join(' and ') end |
#generate_sql_list(attributes = {}) ⇒ Object
designs a list of “Key = Value” pairs combined by “and” or the fillword provided by the block
ORD.generate_sql_list where: 25 , upper: '65'
=> "where = 25 and upper = '65'"
ORD.generate_sql_list( con_id: 25 , symbol: :G) { ',' }
=> "con_id = 25 , symbol = 'G'"
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/support.rb', line 36 def generate_sql_list attributes = {} fill = block_given? ? yield : 'and' attributes.map do |key, value| case value when ActiveOrient::Model "#{key} = #{value.rrid}" when Numeric "#{key} = #{value}" when ::Array "#{key} in [#{value.to_orient}]" when Range "#{key} between #{value.first} and #{value.last} " when DateTime "#{key} = date(\'#{value.strftime("%Y%m%d%H%M%S")}\',\'yyyyMMddHHmmss\')" when Date "#{key} = date(\'#{value.to_s}\',\'yyyy-MM-dd\')" else # String, Symbol, Time, Trueclass, Falseclass ... "#{key} = \'#{value.to_s}\'" end end.join(" #{fill} ") end |