diff options
author | Eric Wong <e@80x24.org> | 2021-06-12 00:10:42 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-06-13 17:39:36 +0000 |
commit | 05cffd40bf094355d19e12aac9a363e796da1702 (patch) | |
tree | ee5f055ff9b7080be03a1ad7e3043c15b34e6f2f /lib/PublicInbox/SharedKV.pm | |
parent | be7da7fd80d9373728476a582d0eec9820a4d424 (diff) | |
download | public-inbox-05cffd40bf094355d19e12aac9a363e796da1702.tar.gz |
We'll be able to use this for shell completion for lei import, lcat, tag, etc.. This also adds --url support for scripting purposes.
Diffstat (limited to 'lib/PublicInbox/SharedKV.pm')
-rw-r--r-- | lib/PublicInbox/SharedKV.pm | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/PublicInbox/SharedKV.pm b/lib/PublicInbox/SharedKV.pm index d65c3158..8347b195 100644 --- a/lib/PublicInbox/SharedKV.pm +++ b/lib/PublicInbox/SharedKV.pm @@ -11,7 +11,7 @@ use parent qw(PublicInbox::Lock); use File::Temp qw(tempdir); use DBI (); use PublicInbox::Spawn; -use File::Path qw(rmtree); +use File::Path qw(rmtree make_path); sub dbh { my ($self, $lock) = @_; @@ -46,8 +46,8 @@ CREATE TABLE IF NOT EXISTS kv ( sub new { my ($cls, $dir, $base, $opt) = @_; my $self = bless { opt => $opt }, $cls; + make_path($dir) if defined($dir) && !-d $dir; $dir //= $self->{"tmp$$.$self"} = tempdir("skv.$$-XXXX", TMPDIR => 1); - -d $dir or mkdir($dir) or die "mkdir($dir): $!"; $base //= ''; my $f = $self->{filename} = "$dir/$base.sqlite3"; $self->{lock_path} = $opt->{lock_path} // "$dir/$base.flock"; @@ -83,6 +83,15 @@ SELECT k,v FROM kv $sth } +sub keys { + my ($self) = @_; + my $sth = $self->dbh->prepare_cached(<<'', undef, 1); +SELECT k FROM kv + + $sth->execute; + map { $_->[0] } @{$sth->fetchall_arrayref}; +} + sub delete_by_val { my ($self, $val, $lock) = @_; $lock //= $self->lock_for_scope_fast; |