1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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:./database/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();
|