Class: DynamicRecordsMeritfront::MultiRowExpression
- Inherits:
-
Object
- Object
- DynamicRecordsMeritfront::MultiRowExpression
- Defined in:
- lib/dynamic-records-meritfront.rb
Instance Attribute Summary collapse
-
#val ⇒ Object
INSERT INTO tests(id, username, is_awesome) VALUES ($0,$1,$2),($3,$4,$5) ON CONFLICT SET is_awesome = true.
Instance Method Summary collapse
- #for_query(key, var_track) ⇒ Object
-
#initialize(val) ⇒ MultiRowExpression
constructor
A new instance of MultiRowExpression.
Constructor Details
#initialize(val) ⇒ MultiRowExpression
Returns a new instance of MultiRowExpression.
140 141 142 143 |
# File 'lib/dynamic-records-meritfront.rb', line 140 def initialize(val) #assuming we are putting in an array of arrays. self.val = val end |
Instance Attribute Details
#val ⇒ Object
INSERT INTO tests(id, username, is_awesome) VALUES ($0,$1,$2),($3,$4,$5) ON CONFLICT SET is_awesome = true
139 140 141 |
# File 'lib/dynamic-records-meritfront.rb', line 139 def val @val end |
Instance Method Details
#for_query(key, var_track) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/dynamic-records-meritfront.rb', line 144 def for_query(key, var_track) #accepts x = current number of variables previously processed #returns ["sql string with $# location information", variables themselves in order, new x] x = -1 db_val = val.map{|attribute_array| "(#{ attribute_array.map{|attribute| if attribute.kind_of? Symbol #allow pointers to other more explicit variables through symbols x = var_track.add_key_value(attribute, nil) else k = "#{key}_#{var_track.next_sql_num.to_s}" x = var_track.add_key_value(k, attribute) end next "$" + x.to_s }.join(",") })"}.join(",") return db_val end |