Skip to content

Instantly share code, notes, and snippets.

@DenKey
Created November 8, 2023 18:42
Show Gist options
  • Save DenKey/6997640ee32feec3235a77eba649a1bb to your computer and use it in GitHub Desktop.
Save DenKey/6997640ee32feec3235a77eba649a1bb to your computer and use it in GitHub Desktop.
def attributes_to_str(attrs)
return nil unless attrs.kind_of?(Hash)
attrs.map {|k,v| k + ' = ' + v}.join(',')
end
def build(attrs)
<<-QUERY
UPDATE Customers
SET #{attributes_to_str(attrs)}
WHERE CustomerID = 1;
QUERY
end
set_attributes = {"ContactName" => 'Alfred Schmidt', "City" => 'Frankfurt'}
puts build(set_attributes)
# Output =>
# UPDATE Customers
# SET ContactName = Alfred Schmidt,City = Frankfurt
# WHERE CustomerID = 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment