bin/example in rack-queries-0.2.1 vs bin/example in rack-queries-0.3.0

- old
+ new

@@ -42,11 +42,11 @@ def values_from(query, binds = []) execute(query, binds).map(&:first) end def rows_from(query, binds = []) - execute(query, binds) + execute(query, binds).to_a end class << self def instance @instance ||= new @@ -120,9 +120,27 @@ WHERE org_id = (SELECT id FROM orgs WHERE name = :org_name) AND active = 1 SQL Database.value_from(query, opts) + end + end + + create do + name 'Name search' + desc 'Search for a user by name' + + opt(:org_name) { Database.values_from('SELECT name FROM orgs') } + opt(:user_name, type: :text) + + run do |opts| + query = <<~SQL + SELECT id, org_id, active, name FROM users + WHERE org_id = (SELECT id FROM orgs WHERE name = :org_name) + AND name LIKE :user_name || '%' + SQL + + [%w[id org_id active name]] + Database.rows_from(query, opts) end end end end