module OrientSupport::Support

Public Instance Methods

as(a=nil) click to toggle source
# File lib/support/orientquery.rb, line 93
def as a=nil
        if a
                @q[:as] = a   # subsequent calls overwrite older entries
        else
                if @q[:as].blank?
                        nil
                else
                        "as: #{ @q[:as] }"
                end
        end
end
compose_where(*arg , &b) click to toggle source
# File lib/support/orientquery.rb, line 20
            def compose_where *arg , &b
                    arg = arg.flatten.compact

                    unless arg.blank? 
                            g= generate_sql_list( arg , &b)
                            "where #{g}" unless g.empty?
                    end
end
generate_sql_list(attributes = {}) { |: 'and'| ... } click to toggle source

designs a list of “Key = Value” pairs combined by “and” or the binding 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'"

If »NULL« should be addressed, { key: nil } is translated to “key = NULL” (used by set: in update and upsert), { key: [nil] } is translated to “key is NULL” ( used by where )

# File lib/support/orientquery.rb, line 40
def generate_sql_list attributes = {},  &b
        fill = block_given? ? yield : 'and'
        case attributes 
        when ::Hash
                attributes.map do |key, value|
                        case value
                        when nil
                                "#{key} =  NULL"
                        when ::Array
                                if value == [nil]
                                "#{key} is NULL"
                                else      
                                "#{key} in #{value.to_orient}"
                                end
                        when Range
                                "#{key} between #{value.first} and #{value.last} " 
                        else #  String, Symbol, Time, Trueclass, Falseclass ...
                                "#{key} = #{value.to_or}"
                        end
                end.join(" #{fill} ")
        when ::Array
                attributes.map{|y| generate_sql_list y, &b }.join( " #{fill} " )
        when String
                attributes
        when Symbol, Numeric
                attributes.to_s
        end          
end