-
-
Save tony-o/06833c25519fdaaf40a0a907def5ae63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
use lib '../p6-db-orm-quicky/lib'; | |
use HTTP::Server::Async; | |
use HTTP::Server::Router; | |
use DB::ORM::Quicky; | |
use JSON::Tiny; | |
my HTTP::Server::Async $server .=new; | |
my DB::ORM::Quicky $orm .=new(:debug); | |
$orm.connect( | |
driver => 'Pg', | |
options => %( | |
database => 'tonyo', | |
), | |
); | |
serve $server; | |
route '/search/:term', -> $req, $res { | |
my $search = $orm.search('version', { | |
module => $req.params<term>, | |
}); | |
my @results; | |
while $search.next -> $module { | |
@results.push(%( | |
qw<version version author author commit_id commit module module>.map(-> $db, $key { | |
$key => $module.get($db) | |
}); | |
)); | |
} | |
$res.close(to-json(@results)); | |
}; | |
$server.listen(True); | |
# vi:syntax=perl6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment