Last active
August 29, 2015 14:15
-
-
Save preaction/3d47ac7429e8bd12488b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package DbLibTry; | |
use Mojo::Base '-strict'; | |
use DBI; | |
has dbh => sub { | |
DBI->connect( "DBI:SQLite:dbname=songdb.sqlite3", q{}, q{}, {RaiseError => 1} ) | |
or die $DBI::errstr; | |
}; | |
sub get_all_songs { | |
my $self = shift; | |
return $self->dbh->selectall_hashref('select * from songs;', 'id'); # Assuming your id field is called "id" | |
} |
This file contains hidden or 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
use DbLibTry; | |
my $test_dbh = DBI->connect( "DBI:SQLite:dbname=test.sqlite3" ); | |
# Insert some test data | |
$test_dbh->do( "INSERT INTO songs (id, name) VALUES (1, 'hello')" ); | |
my $obj = DbLibTry->new( dbh => $test_dbh ); | |
$obj->get_all_songs; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment