AC-Yenta
view release on metacpan or search on metacpan
lib/AC/Yenta/Store/SQLite.pm view on Meta::CPAN
$map, $sub, $key, $end);
}else{
$st = _do($me->{db}, 'select key as k, value as v from ykv where map = ? and sub = ? and key >= ?',
$map, $sub, $key);
}
my $r = $st->fetchall_arrayref({});
return @$r;
}
################################################################
sub _init {
my $db = shift;
eval {
for my $sql (split /;/, $initsql){
$sql =~ s/--\s.*$//gm; # remove comments
next unless $sql !~ /^\s*$/;
_do($db, $sql);
}
};
if(my $e=$@){
# QQQ?
problem("error initializing sqlite db: $e");
}
}
sub _do {
my $db = shift;
my $sql = shift;
my( $st, $nrow );
eval {
debug("sql: $sql");
$st = $db->prepare( $sql );
$nrow = $st->execute( @_ );
};
my $e = $@;
die $e if $e;
return $st;
}
################################################################
$initsql = <<END;
create table if not exists ykv (
map text not null,
sub text not null,
key text not null,
value text,
unique(map,sub,key)
);
create index if not exists ykvidx on ykv(map, sub, key);
pragma synchronous = 1; -- default is full(2)
pragma cache_size = 100000; -- default is 2000
vacuum;
analyze;
END
;
1;
( run in 1.433 second using v1.01-cache-2.11-cpan-39bf76dae61 )