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;
|