8 if(scalar @ARGV == 0 or $ARGV[0] =~ /^-?-[h?]/i)
10 print "LevelDB - Commandline Interface for Google's leveldb key-value storage,
11 based on Tie::LeveDB(3pm)
12 Usage: LevelDB <leveldb-directory> <command> [<key> [<value>]]
14 check exit zero if <leveldb-directory> is a valid leveldb
15 open try to open the database, exit non-zero if failed
17 keys enumerate all keys line-by-line
18 show display all keys and values in KEY<TAB>VALUE<LF> format
19 get KEY print the value of KEY
21 set KEY VAL set the value of KEY to VAL unless already equals to VAL
22 default KEY VAL set the value of KEY unless KEY is already set
23 replace KEY VAL set the value of KEY unless KEY does not exist
24 alter KEY VAL same as 'set' but force writes
27 merge [FILE] import all key-value pairs from FILE or STDIN in KEY<TAB>VALUE<LF> format
28 merge-default [FILE] same as 'merge' but sets only unset keys
29 merge-replace [FILE] same as 'merge' but sets only already existing keys
35 if($ARGV[1] eq 'check')
37 if(-f
$ARGV[0]."/LOG" and -f
$ARGV[0]."/CURRENT")
39 eval { new Tie
::LevelDB
::DB
($ARGV[0]); 1; };
42 if($@
=~ /^IO error: lock/)
55 return !! grep {$_ eq $_[0]} keys %DB;
58 if($ARGV[1] =~ /^(keys|show|merge|merge-default|merge-replace|get|set|alter|replace|default|del|open)$/)
60 tie
%DB, 'Tie::LevelDB', $ARGV[0];
66 print "$_\n" for sort {lc $a cmp lc $b} keys %DB;
70 print "$_\t$DB{$_}\n" for sort {lc $a cmp lc $b} keys %DB;
76 open $fh, '<', $ARGV[2] or die $!;
85 if(my ($key, $value) = /^(.+?)\t(.*)$/)
91 if(not keyexists
($key) or $DB{$key} ne $value)
98 if(not keyexists
($key))
103 when('merge-replace')
105 if(keyexists
($key) and $DB{$key} ne $value)
114 warn "Invalid input: $_";
124 $DB{$ARGV[2]} = $ARGV[3];
128 if(not keyexists
($ARGV[2]) or $DB{$ARGV[2]} ne $ARGV[3])
130 $DB{$ARGV[2]} = $ARGV[3];
135 if(keyexists
($ARGV[2]))
137 $DB{$ARGV[2]} = $ARGV[3];
142 if(not keyexists
($ARGV[2]))
144 $DB{$ARGV[2]} = $ARGV[3];
149 delete $DB{$ARGV[2]};
159 warn "Invalid command: $ARGV[1]\n";
169 LevelDB - Commandline interface for Google's leveldb key-value storage