Skip to content

Instantly share code, notes, and snippets.

@adcpe
Created May 16, 2020 19:23
Show Gist options
  • Save adcpe/a355bfc02b73f0ded92c3611b3a4baad to your computer and use it in GitHub Desktop.
Save adcpe/a355bfc02b73f0ded92c3611b3a4baad to your computer and use it in GitHub Desktop.
def filtered_list(filter_name, filter_value)
puts "#{filter_name} - #{filter_value}"
query = %(SELECT name, type, city FROM restaurants\n)
if filter_name.nil? && filter_value.nil?
query << "ORDER BY name ASC;"
else
query << %(WHERE LOWER(#{filter_name}) LIKE '%#{filter_value}%' ORDER BY name ASC;)
end
response = @conn.exec(query).to_a
query_to_table(response)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment