1 package App::IdiotBox::Store::SQLite;
4 use warnings FATAL => 'all';
6 use DBIx::Data::Store::CRUD;
7 use App::IdiotBox::DataSet;
8 use Scalar::Util qw(weaken);
13 recent_announcements => {
16 my ($self, $obj) = @_;
17 bless($obj, 'App::IdiotBox::Announcement');
18 bless($obj->{bucket}, 'App::IdiotBox::Bucket');
22 my ($self, $obj) = @_;
33 my ($self, $obj) = @_;
34 bless($obj, 'App::IdiotBox::Bucket');
35 weaken (my $weak = $obj);
36 $obj->{videos} = _bind_set('bucket_videos',
38 raw_store => $self->_store->raw_store,
39 implicit_arguments => { bucket_slug => $obj->{slug} },
44 my ($self, $obj) = @_;
45 bless($obj, 'App::IdiotBox::Video');
46 weaken($obj->{bucket} = $weak);
50 my ($self, $obj) = @_;
61 my ($self, $obj) = @_;
67 set_over => [ 'slug' ],
70 set_over => [ 'slug' ]
75 recent_announcements => {
76 select_column_order => [ qw(
77 id made_at video_count bucket.slug bucket.name bucket.video_count
81 announcement.id, announcement.made_at, COUNT(DISTINCT my_videos.slug),
82 bucket.slug, bucket.name, COUNT(DISTINCT all_videos.slug)
84 announcements announcement
86 ON bucket.slug = announcement.bucket_slug
88 ON my_videos.announcement_id = announcement.id
89 JOIN videos all_videos
90 ON all_videos.bucket_slug = announcement.bucket_slug
91 JOIN announcements all_announcements
92 ON all_announcements.bucket_slug = announcement.bucket_slug
94 announcement.made_at, bucket.slug, bucket.name
96 announcement.made_at = MAX(all_announcements.made_at)
98 announcement.made_at DESC
102 select_column_order => [ qw(slug name) ],
103 select_single_sql => q{
108 select_single_argument_order => [ 'slug' ],
111 select_column_order => [ qw(slug name author details) ],
113 SELECT slug, name, author, details
115 WHERE bucket_slug = ?
117 select_argument_order => [ 'bucket_slug' ],
118 select_single_sql => q{
119 SELECT slug, name, author, details
121 WHERE bucket_slug = ? AND slug = ?
123 select_single_argument_order => [ qw(bucket_slug slug) ],
128 my ($class, $idiotbox) = @_;
129 bless({ idiotbox => $idiotbox }, $class)->_bind;
132 my $DSN = 'dbi:SQLite:idiotbox.db';
135 DBIx::Data::Store->connect($DSN);
140 my $idiotbox = $self->{idiotbox};
142 my $db_store = $self->_new_db_store;
144 foreach my $to_bind (qw(recent_announcements buckets)) {
145 $idiotbox->{$to_bind} = _bind_set($to_bind, { raw_store => $db_store });
151 my ($type, $store_args, $set_args) = @_;
152 my $store = DBIx::Data::Store::CRUD->new({
156 return App::IdiotBox::DataSet->new({