summaryrefslogtreecommitdiff
path: root/journal_dbic_example.pm
diff options
context:
space:
mode:
Diffstat (limited to 'journal_dbic_example.pm')
-rw-r--r--journal_dbic_example.pm39
1 files changed, 39 insertions, 0 deletions
diff --git a/journal_dbic_example.pm b/journal_dbic_example.pm
new file mode 100644
index 0000000..bef900a
--- /dev/null
+++ b/journal_dbic_example.pm
@@ -0,0 +1,39 @@
+package journalsDBIC;
+use Data::Dumper;
+
+#insert entry by hashref
+my $journalentry = $schema->resultset('Journals')->create({
+ date => time(),
+ fulltext => "Hello world",
+ image_url => "http://something/"
+});
+
+
+#delete by id
+my $journalentry = $schema->resultset('Journals')->find({ id => 1 });
+$journalentry->delete();
+
+#update by hashref
+my $journalentry = $schema->resultset('Journals')->find({ id => 1 });
+$journalentry->update({
+ fulltext => "New text here",
+});
+
+#select by date
+my $res = $schema->resultset('Journals')->search({
+ -and => [
+ date => [ '>', DateTime->now()->subtract({days => 2}) ],
+ date => [ '<', DateTime->now() ],
+ ]
+});
+foreach my $row ($res->all){
+ print Dumper $row;
+}
+
+#select *
+#select * from journals basically dump the whole table
+my $res = $schema->resultset('Journals')
+foreach my $row ($res->all){
+ print Dumper { $row->get_columns };
+}
+1;