app.pl 704 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env perl
  2. use Kelp::Less;
  3. use DBI;
  4. my $dsn = "dbi:mysql:database=hello_world;host=localhost;port=3306";
  5. my $dbh = DBI->connect( $dsn, 'benchmarkdbuser', 'benchmarkdbpass', {} );
  6. my $sth = $dbh->prepare("SELECT * FROM World where id = ?");
  7. get '/json' => sub {
  8. { message => 'Hello, World!' }
  9. };
  10. get '/db' => sub {
  11. my $self = shift;
  12. my $queries = $self->param('queries') || 1;
  13. my @response;
  14. for ( 1 .. $queries ) {
  15. my $id = int rand 10000 + 1;
  16. $sth->execute($id);
  17. if ( my $row = $sth->fetchrow_hashref ) {
  18. push @response,
  19. { id => $id, randomNumber => $row->{randomNumber} };
  20. }
  21. }
  22. return \@response;
  23. };
  24. run;