From f68564b88dfb3ac08df2d01f883a0276883b96aa Mon Sep 17 00:00:00 2001 From: yo mama Date: Thu, 25 Sep 2014 19:09:06 -0700 Subject: added2 --- DBIC_tests.pl | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 DBIC_tests.pl (limited to 'DBIC_tests.pl') diff --git a/DBIC_tests.pl b/DBIC_tests.pl new file mode 100644 index 0000000..ec532d4 --- /dev/null +++ b/DBIC_tests.pl @@ -0,0 +1,56 @@ +#!/usr/bin/perl +use Data::Dumper; +use DateTime;#is that what was missing? could be +use lib 'lib'; +use JournalApp::Schema; + +my $entry = { + id => 12, + fulltext => "hello world test test test", + image_url => "http://myimage.com/new.png", + date => DateTime->now()->epoch, +}; +#our $schema = JournalApp::Schema->connect( 'dbi:SQLite:./journals.db', '', ''); +our $schema = JournalApp::Schema->connect( 'dbi:mysql:database=journal;host=localhost;port=3306', 'journal_user', 'journal_password', { + quote_names => 1 +}); + +sub test_remove_from_db{ + #delete by id + my $journalentry = $schema->resultset('Journal')->find({ id => $entry->{id} }); + +$journalentry->delete(); +} + + + +sub test_get_entry_by_date{ + my $res = $schema->resultset('Journal')->search({ + -and => [ + date => { '>', DateTime->now()->epoch - 3600 * 24 * 2 }, + date => { '<=', DateTime->now()->epoch }, + ] + }, { + order_by => "date" + } + ); + foreach my $row ($res->all){ + print Dumper $row->id; #so it just didn't find anything? looks so yeah just needed <= + } + +} + +sub test_add_journal_entry{ + my $journalentry = $schema->resultset('Journal')->create($entry); + if ($journalentry){ print "added sucessfully\n"} else { "add failed\n" }; + return $journalentry; +} + +#how do I connect? + +sub main{ + test_add_journal_entry; + test_get_entry_by_date; + test_remove_from_db; +} +main(); -- cgit v1.2.3-70-g09d2