pgldb 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/pgldb +26 -13
- data/lib/ldb_engin.rb +24 -0
- data/lib/pgldb.rb +2 -0
- data/lib/pgldb/version.rb +1 -1
- metadata +4 -3
data/bin/pgldb
CHANGED
@@ -1,13 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'gli'
|
3
|
-
begin # XXX: Remove this begin/rescue before distributing your app
|
4
3
|
require 'pgldb'
|
5
|
-
rescue LoadError
|
6
|
-
STDERR.puts "In development, you need to use `bundle exec bin/pgldb` to run your app"
|
7
|
-
STDERR.puts "At install-time, RubyGems will make sure lib, etc. are in the load path"
|
8
|
-
STDERR.puts "Feel free to remove this message from bin/pgldb now"
|
9
|
-
exit 64
|
10
|
-
end
|
11
4
|
|
12
5
|
include GLI::App
|
13
6
|
|
@@ -33,13 +26,31 @@ command :start do |c|
|
|
33
26
|
c.default_value 'default'
|
34
27
|
c.flag :f
|
35
28
|
c.action do |global_options,options,args|
|
29
|
+
puts 'nothting to do'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'Describe start here'
|
34
|
+
arg_name 'Describe arguments to start here'
|
35
|
+
command :dump do |c|
|
36
|
+
c.desc 'Describe a switch to start'
|
37
|
+
c.switch :s
|
38
|
+
|
39
|
+
c.desc 'Describe a flag to start'
|
40
|
+
c.default_value 'default'
|
41
|
+
c.flag :f
|
42
|
+
c.action do |global_options,options,args|
|
43
|
+
raise 'pgldb dump db-dir [row count] [key byte] [value byte]' unless args[0]
|
44
|
+
ldb = LdbEngin.new(args[0])
|
36
45
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
46
|
+
rowcount = 1000
|
47
|
+
keybyte = 16
|
48
|
+
valuebyte = 100
|
49
|
+
rowcount = args[1].to_i if args[1]
|
50
|
+
keybyte = args[2].to_i if args[2]
|
51
|
+
valuebyte = args[3].to_i if args[3]
|
41
52
|
|
42
|
-
|
53
|
+
ldb.dump rowcount, keybyte, valuebyte
|
43
54
|
end
|
44
55
|
end
|
45
56
|
|
@@ -61,7 +72,9 @@ end
|
|
61
72
|
on_error do |exception|
|
62
73
|
# Error logic here
|
63
74
|
# return false to skip default error handling
|
64
|
-
|
75
|
+
puts exception.message
|
76
|
+
puts exception.backtrace
|
77
|
+
false
|
65
78
|
end
|
66
79
|
|
67
80
|
exit run(ARGV)
|
data/lib/ldb_engin.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'leveldb'
|
4
|
+
|
5
|
+
class LdbEngin
|
6
|
+
def initialize(dbdir)
|
7
|
+
@db = LevelDB::DB.new dbdir
|
8
|
+
end
|
9
|
+
|
10
|
+
def dump(rowcount, keybyte, valuebyte)
|
11
|
+
raise "keybyte(#{keybyte}) is too small for #{rowcount} rows." if rowcount.to_s.length > keybyte
|
12
|
+
|
13
|
+
|
14
|
+
puts "dump level-db with #{rowcount} rows. key = #{keybyte} bytes, value = #{valuebyte} bytes."
|
15
|
+
tstart = Time.new
|
16
|
+
(0..rowcount).each do |id|
|
17
|
+
key = id.to_s.rjust(keybyte, '0')
|
18
|
+
value = id.to_s.rjust(valuebyte, '-')
|
19
|
+
@db[key] = value
|
20
|
+
end
|
21
|
+
puts "dump finished. #{Time.new - tstart} seconds elapsed."
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/pgldb.rb
CHANGED
data/lib/pgldb/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pgldb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- bin/pgldb
|
88
88
|
- lib/pgldb/version.rb
|
89
89
|
- lib/pgldb.rb
|
90
|
+
- lib/ldb_engin.rb
|
90
91
|
- README.rdoc
|
91
92
|
- pgldb.rdoc
|
92
93
|
homepage: http://your.website.com
|
@@ -109,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
110
|
version: '0'
|
110
111
|
segments:
|
111
112
|
- 0
|
112
|
-
hash:
|
113
|
+
hash: 892945757456173270
|
113
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
115
|
none: false
|
115
116
|
requirements:
|
@@ -118,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
119
|
version: '0'
|
119
120
|
segments:
|
120
121
|
- 0
|
121
|
-
hash:
|
122
|
+
hash: 892945757456173270
|
122
123
|
requirements: []
|
123
124
|
rubyforge_project:
|
124
125
|
rubygems_version: 1.8.25
|