BusyBird

 view release on metacpan or  search on metacpan

lib/BusyBird/StatusStorage/SQLite.pm  view on Meta::CPAN

            $sth->execute(@bind);
            my $result = $sth->fetchall_arrayref();
            if(!defined($result)) {
                confess "Statement handle is inactive. Something is wrong.";
            }
            if(@$result) {
                push @ret_contained, $query_elem;
            }else {
                push @ret_not_contained, $query_elem;
            }
        }
        return (undef, \@ret_contained, \@ret_not_contained);
    }catch {
        my $e = shift;
        return ($e);
    };
    @_ = @method_result;
    goto $callback;
}

sub get_timeline_names {
    my ($self) = @_;
    my $dbh = $self->_get_my_dbh();
    my ($sql, @bind) = $self->{maker}->select(
        'timelines', ['name']
    );
    my $result = $dbh->selectall_arrayref($sql, undef, @bind);
    my @return = map { $_->[0] } @$result;
    return @return;
}

1;

__END__

=pod

=head1 NAME

BusyBird::StatusStorage::SQLite - status storage in SQLite database

=head1 SYNOPSIS

    use BusyBird;
    use BusyBird::StatusStorage::SQLite;
    
    my $storage = BusyBird::StatusStorage::SQLite->new(
        path => 'path/to/storage.sqlite3',
        max_status_num => 5000
    );
    
    busybird->set_config(
        default_status_storage => $storage
    );

=head1 DESCRIPTION

This is an implementation of L<BusyBird::StatusStorage> interface.
It stores statuses in an SQLite database.

This storage is synchronous, i.e., all operations block the thread
and the callback is called before the method returns.

=head1 CLASS METHOD

=head2 $storage = BusyBird::StatusStorage::SQLite->new(%args)

The constructor.

Fields in C<%args> are:

=over

=item C<path> => FILE_PATH (mandatory)

Path string to the SQLite database file.
If C<':memory:'> is specified, it creates a temporary in-memory storage.

=item C<max_status_num> => INT (optional, default: 2000)

The maximum number of statuses the storage guarantees to store per timeline.
You cannot expect a timeline to keep more statuses than this number.

=item C<hard_max_status_num> => INT (optional, default: 120% of max_status_num)

The hard limit max number of statuses the storage is able to store per timeline.
When the number of statuses in a timeline exceeds this number,
it deletes old statuses from the timeline so that the timeline has C<max_status_num> statuses.

=item C<vacuum_on_delete> => INT (optional, default: 200% of max_status_num)

The status storage automatically executes C<VACUUM> every time this number of statuses are
deleted from the storage. B<The number is for the whole storage, not per timeline>.

If you set this option less than or equal to 0, it never C<VACUUM> itself.


=back

=head1 OBJECT METHODS

L<BusyBird::StatusStorage::SQLite> implements all object methods in L<BusyBird::StatusStorage>.
In addition to it, it has the following methods.

=head2 $storage->vacuum()

Executes SQL C<VACUUM> on the database.

=head2 @timeline_names = $storage->get_timeline_names()

Returns all timeline names in the C<$storage>.


=head1 AUTHOR

Toshio Ito C<< <toshioito [at] cpan.org> >>

=cut



( run in 0.959 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )