File: Posts.pm

package info (click to toggle)
libmojo-sqlite-perl 3.009-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 324 kB
  • sloc: perl: 610; sql: 11; makefile: 6
file content (28 lines) | stat: -rw-r--r-- 545 bytes parent folder | download | duplicates (3)
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
package Blog::Model::Posts;
use Mojo::Base -base;

has 'sqlite';

sub add {
  my ($self, $post) = @_;
  return $self->sqlite->db->insert('posts', $post)->last_insert_id;
}

sub all { shift->sqlite->db->select('posts')->hashes->to_array }

sub find {
  my ($self, $id) = @_;
  return $self->sqlite->db->select('posts', undef, {id => $id})->hash;
}

sub remove {
  my ($self, $id) = @_;
  $self->sqlite->db->delete('posts', {id => $id});
}

sub save {
  my ($self, $id, $post) = @_;
  $self->sqlite->db->update('posts', $post, {id => $id});
}

1;