Skip to content

Instantly share code, notes, and snippets.

@zdavatz
Created March 14, 2011 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zdavatz/869335 to your computer and use it in GitHub Desktop.
Save zdavatz/869335 to your computer and use it in GitHub Desktop.
storage.rb
def update_condition_index(index_name, origin_id, search_terms, target_id)
keys = []
vals = []
search_terms.each { |key, val|
keys.push(key)
vals.push(val)
}
if(target_id)
self.dbi.do <<-SQL, origin_id, target_id, *vals
INSERT INTO #{index_name} (origin_id, target_id, #{keys.join(', ')})
VALUES (?, ?#{', ?' * keys.size})
SQL
else
key_str = keys.collect { |key| "#{key}=?" }.join(', ')
self.dbi.do <<-SQL, *(vals.push(origin_id))
UPDATE #{index_name} SET #{key_str}
WHERE origin_id = ?
SQL
end
end
@zdavatz
Copy link
Author

zdavatz commented Mar 14, 2011

In red is the SQL syntax grammar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment