Brackup
view release on metacpan or search on metacpan
lib/Brackup/Dict/SQLite2.pm view on Meta::CPAN
return $self;
}
sub get {
my ($self, $key) = @_;
$self->{get_sth}->bind_param(1, $key);
$self->{get_sth}->execute;
my ($val) = $self->{get_sth}->fetchrow_array;
return $val;
}
sub set {
my ($self, $key, $val) = @_;
$self->{dbh}->do("REPLACE INTO $self->{table} VALUES (?,?)", undef, $key, $val);
return 1;
}
# Iterator interface, returning ($key, $value), and () on eod
sub each {
my $self = shift;
if (! $self->{each_sth}) {
$self->{each_sth} = $self->{dbh}->prepare("SELECT key, value from $self->{table}");
$self->{each_sth}->execute;
}
my ($k, $v) = $self->{each_sth}->fetchrow_array;
return wantarray ? ($k, $v) : $k if defined $k;
return wantarray ? () : undef;
}
sub delete {
my ($self, $key) = @_;
$self->{dbh}->do("DELETE FROM $self->{table} WHERE key = ?", undef, $key);
return 1;
}
sub count {
my $self = shift;
my ($count) = $self->{dbh}->selectrow_array("SELECT COUNT(key) FROM $self->{table}");
return $count;
}
sub backing_file {
my $self = shift;
return $self->{file};
}
1;
=head1 NAME
Brackup::Dict::SQLite2 - key-value dictionary implementation, using a
SQLite database for storage (lighter/slower version of
Brackup::Dict::SQLite)
=head1 DESCRIPTION
Brackup::Dict::SQLite2 implements a simple key-value dictionary using
a SQLite database for storage. Brackup::Dict::SQLite2 is identical to
L<Brackup::Dict::SQLite> (so see that for more details), but it uses
conventional database cursors/iterators for all operations, instead of
pre-loading the entire database into memory. As such, it is slightly
slower than Brackup::Dict::SQLite, but uses much less memory.
See L<Brackup::DigestCache> and L<Brackup::InventoryDatabase> for
how to manually specify the dictionary class to use.
=head1 SEE ALSO
L<brackup>
L<Brackup>
L<Brackup::Dict::SQLite>
=cut
( run in 2.903 seconds using v1.01-cache-2.11-cpan-cdf2f3d4e48 )