bin/example in rack-queries-0.1.3 vs bin/example in rack-queries-0.2.0

- old
+ new

@@ -66,10 +66,18 @@ end end module Queries class OrgCountQuery + def self.name + 'Organization count' + end + + def self.desc + 'The total count of organizations in the system' + end + def run(_opts) Database.value_from('SELECT COUNT(*) FROM orgs') end end @@ -107,25 +115,27 @@ class UserCountQuery def run(_opts) Database.value_from('SELECT COUNT(*) FROM users') end end - - class UsersQuery - def run(_opts) - [%w[id org_id active name]] + - Database.rows_from('SELECT id, org_id, active, name FROM users') - end - end end Rack::Queries.add( Queries::OrgCountQuery, Queries::OrgUsersCountQuery, Queries::OrgActiveUsersCountQuery, - Queries::UserCountQuery, - Queries::UsersQuery + Queries::UserCountQuery ) + +Rack::Queries.create do + name 'UsersQuery' + desc 'The list of all users' + + run do |_opts| + [%w[id org_id active name]] + + Database.rows_from('SELECT id, org_id, active, name FROM users') + end +end Rack::Server.start(app: Rack::Queries::App, server: 'webrick') __END__ CREATE TABLE orgs (