use strict;
use warnings;
use Data::Dumper;
use feature qw(say);

&db_query("SELECT `ID`, `NAME`, `HREF` FROM `venues`", $connection, 'selectall_hashref', 'ID');

sub db_query {
    # &Delimiter((caller(0))[3]); 
    my ($query, $connection, $switch, @rest) = @_;
    my $response;
    
    # say 'DATABASE CONNECTION STATE: ' . $connection->ping;

    my $statement;
    if ($switch eq 'fetchrow') {
        $statement = $connection->prepare($query);
        $statement->execute();
        $response = $statement->fetchrow();
    }
    elsif ($switch eq 'do') {
        $response = $connection->do($query) or die $connection->errstr;
        $connection->do($query, sub {
            my ($rv, $dbh) = @_;
            print Dumper $rv;
            print Dumper $dbh;
        });
    }
    elsif ($switch eq 'selectall_hashref') {
        # $response = $connection->selectall_hashref($query, $rest[0]) or die $connection->errstr;
        $connection->selectall_hashref($query, sub {
            ($response) = @_;
        });
    }
    elsif ($switch eq 'selectall_arrayref') {
        # $response = $connection->selectall_arrayref($query) or die $connection->errstr;
        $connection->selectall_arrayref($query, sub {
            ($response) = @_;
        });
    }
    $statement->finish if $statement;
    
    print Dumper $response;
    die;
    return $response;
}