module Babik::QuerySet::Update::Assignment
Field assignment module
Public Class Methods
_escape(str)
click to toggle source
Escape a value for database @param str [String] original string value. @return [String] escaped string value.
# File lib/babik/queryset/lib/update/assignment.rb, line 40 def self._escape(str) Babik::Database.escape(str) end
sql_field(model, field)
click to toggle source
Return the field prepared for the UPDATE operation. Used when rendering the SQL template @param model [ActiveRecord::Base] model this field belongs to. @param field [String] field to be updated. @return [String] Field prepared to be inserted in the left part of a SQL UPDATE assignment.
# File lib/babik/queryset/lib/update/assignment.rb, line 15 def self.sql_field(model, field) field = Babik::Table::Field.new(model, field) field.real_field end
sql_value(update_field_value)
click to toggle source
Return the value prepared for the UPDATE operation. Used when rendering the SQL template @param update_field_value [Operation, Function
, String, ActiveRecord::BASE] field to be updated.
if Operation, an arithmetic operation based on other field of the record will be applied (+, -, * ...) if Function, a function will be called. The parameters of the function can ben any other field of the record. if String, a escaped version of the value will be returned. if ActiveRecord::Base, the id of the object will be returned. Otherwise, the value as-is will be returned.
@return [String] Field prepared to be inserted in the left part of a SQL UPDATE assignment.
# File lib/babik/queryset/lib/update/assignment.rb, line 30 def self.sql_value(update_field_value) return update_field_value.sql_value if update_field_value.is_a?(Operation) || update_field_value.is_a?(Function) return _escape(update_field_value) if update_field_value.is_a?(String) return update_field_value.id if update_field_value.is_a?(ActiveRecord::Base) update_field_value end