leveldb-ruby 0.1 → 0.2
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/README +11 -0
- data/ext/leveldb/leveldb.cc +13 -11
- metadata +101 -117
data/README
CHANGED
@@ -15,3 +15,14 @@ And then run this:
|
|
15
15
|
db.get "it"
|
16
16
|
|
17
17
|
Only a very few operations are supported right now:
|
18
|
+
|
19
|
+
DB.new # creates or loads as necessary
|
20
|
+
DB.create # dies if it already exists
|
21
|
+
DB.load # dies unless it alread exists
|
22
|
+
|
23
|
+
DB#get # alias: DB#[]
|
24
|
+
DB#put # alias: DB#[]=
|
25
|
+
DB#delete
|
26
|
+
|
27
|
+
DB#each
|
28
|
+
... and all the enumerable methods
|
data/ext/leveldb/leveldb.cc
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#include <ruby.h>
|
2
2
|
|
3
3
|
#include "leveldb/db.h"
|
4
|
-
#include "leveldb/
|
4
|
+
#include "leveldb/slice.h"
|
5
5
|
|
6
6
|
static VALUE m_leveldb;
|
7
7
|
static VALUE c_db;
|
@@ -56,19 +56,22 @@ static VALUE db_close(VALUE self) {
|
|
56
56
|
return Qtrue;
|
57
57
|
}
|
58
58
|
|
59
|
+
#define RUBY_STRING_TO_SLICE(x) leveldb::Slice(RSTRING_PTR(x), RSTRING_LEN(x))
|
60
|
+
#define SLICE_TO_RUBY_STRING(x) rb_str_new(x.data(), x.size())
|
61
|
+
#define STRING_TO_RUBY_STRING(x) rb_str_new(x.data(), x.size())
|
59
62
|
static VALUE db_get(VALUE self, VALUE v_key) {
|
60
63
|
Check_Type(v_key, T_STRING);
|
61
64
|
|
62
65
|
bound_db* db;
|
63
66
|
Data_Get_Struct(self, bound_db, db);
|
64
67
|
|
65
|
-
|
68
|
+
leveldb::Slice key = RUBY_STRING_TO_SLICE(v_key);
|
66
69
|
std::string value;
|
67
70
|
leveldb::Status status = db->db->Get(leveldb::ReadOptions(), key, &value);
|
68
71
|
if(status.IsNotFound()) return Qnil;
|
69
72
|
|
70
73
|
RAISE_ON_ERROR(status);
|
71
|
-
return
|
74
|
+
return STRING_TO_RUBY_STRING(value);
|
72
75
|
}
|
73
76
|
|
74
77
|
static VALUE db_delete(VALUE self, VALUE v_key) {
|
@@ -77,7 +80,7 @@ static VALUE db_delete(VALUE self, VALUE v_key) {
|
|
77
80
|
bound_db* db;
|
78
81
|
Data_Get_Struct(self, bound_db, db);
|
79
82
|
|
80
|
-
|
83
|
+
leveldb::Slice key = RUBY_STRING_TO_SLICE(v_key);
|
81
84
|
std::string value;
|
82
85
|
leveldb::Status status = db->db->Get(leveldb::ReadOptions(), key, &value);
|
83
86
|
|
@@ -86,7 +89,7 @@ static VALUE db_delete(VALUE self, VALUE v_key) {
|
|
86
89
|
status = db->db->Delete(leveldb::WriteOptions(), key);
|
87
90
|
RAISE_ON_ERROR(status);
|
88
91
|
|
89
|
-
return
|
92
|
+
return STRING_TO_RUBY_STRING(value);
|
90
93
|
}
|
91
94
|
|
92
95
|
static VALUE db_exists(VALUE self, VALUE v_key) {
|
@@ -95,7 +98,7 @@ static VALUE db_exists(VALUE self, VALUE v_key) {
|
|
95
98
|
bound_db* db;
|
96
99
|
Data_Get_Struct(self, bound_db, db);
|
97
100
|
|
98
|
-
|
101
|
+
leveldb::Slice key = RUBY_STRING_TO_SLICE(v_key);
|
99
102
|
std::string value;
|
100
103
|
leveldb::Status status = db->db->Get(leveldb::ReadOptions(), key, &value);
|
101
104
|
|
@@ -110,9 +113,8 @@ static VALUE db_put(VALUE self, VALUE v_key, VALUE v_value) {
|
|
110
113
|
bound_db* db;
|
111
114
|
Data_Get_Struct(self, bound_db, db);
|
112
115
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
+
leveldb::Slice key = RUBY_STRING_TO_SLICE(v_key);
|
117
|
+
leveldb::Slice value = RUBY_STRING_TO_SLICE(v_value);
|
116
118
|
leveldb::Status status = db->db->Put(leveldb::WriteOptions(), key, value);
|
117
119
|
|
118
120
|
RAISE_ON_ERROR(status);
|
@@ -140,8 +142,8 @@ static VALUE db_each(VALUE self) {
|
|
140
142
|
leveldb::Iterator* it = db->db->NewIterator(leveldb::ReadOptions());
|
141
143
|
|
142
144
|
for (it->SeekToFirst(); it->Valid(); it->Next()) {
|
143
|
-
VALUE key =
|
144
|
-
VALUE value =
|
145
|
+
VALUE key = SLICE_TO_RUBY_STRING(it->key());
|
146
|
+
VALUE value = SLICE_TO_RUBY_STRING(it->value());
|
145
147
|
VALUE ary = rb_ary_new2(2);
|
146
148
|
rb_ary_push(ary, key);
|
147
149
|
rb_ary_push(ary, value);
|
metadata
CHANGED
@@ -1,183 +1,167 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: leveldb-ruby
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.2'
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
version: "0.1"
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- William Morgan
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
date: 2011-06-16 22:35:18 -07:00
|
12
|
+
date: 2011-06-17 15:04:29.000000000 -07:00
|
18
13
|
default_executable:
|
19
14
|
dependencies: []
|
20
|
-
|
21
15
|
description: LevelDB-Ruby is a Ruby binding to LevelDB.
|
22
16
|
email: wmorgan-leveldb-ruby-gemspec@masanjin.net
|
23
17
|
executables: []
|
24
|
-
|
25
|
-
extensions:
|
18
|
+
extensions:
|
26
19
|
- ext/leveldb/extconf.rb
|
27
|
-
extra_rdoc_files:
|
20
|
+
extra_rdoc_files:
|
28
21
|
- README
|
29
22
|
- ext/leveldb/leveldb.cc
|
30
|
-
files:
|
23
|
+
files:
|
31
24
|
- README
|
32
25
|
- ext/leveldb/extconf.rb
|
33
26
|
- lib/leveldb.rb
|
34
27
|
- ext/leveldb/leveldb.cc
|
35
28
|
- leveldb/Makefile
|
36
|
-
- leveldb/
|
37
|
-
- leveldb/
|
38
|
-
- leveldb/port/port_android.h
|
39
|
-
- leveldb/port/sha1_test.cc
|
40
|
-
- leveldb/port/port_chromium.h
|
41
|
-
- leveldb/port/port_chromium.cc
|
42
|
-
- leveldb/port/port_posix.h
|
43
|
-
- leveldb/port/sha1_portable.cc
|
44
|
-
- leveldb/port/port_example.h
|
45
|
-
- leveldb/port/port_posix.cc
|
46
|
-
- leveldb/port/port.h
|
47
|
-
- leveldb/port/sha1_portable.h
|
48
|
-
- leveldb/port/port_android.cc
|
49
|
-
- leveldb/port/port_osx.cc
|
50
|
-
- leveldb/db/dbformat.cc
|
51
|
-
- leveldb/db/db_test.cc
|
52
|
-
- leveldb/db/write_batch_internal.h
|
53
|
-
- leveldb/db/db_impl.h
|
54
|
-
- leveldb/db/log_writer.cc
|
55
|
-
- leveldb/db/write_batch.cc
|
29
|
+
- leveldb/db/builder.cc
|
30
|
+
- leveldb/db/builder.h
|
56
31
|
- leveldb/db/corruption_test.cc
|
57
|
-
- leveldb/db/db_impl.cc
|
58
|
-
- leveldb/db/filename.h
|
59
|
-
- leveldb/db/skiplist.h
|
60
|
-
- leveldb/db/table_cache.cc
|
61
|
-
- leveldb/db/log_test.cc
|
62
|
-
- leveldb/db/log_reader.h
|
63
32
|
- leveldb/db/db_bench.cc
|
64
|
-
- leveldb/db/
|
33
|
+
- leveldb/db/db_impl.cc
|
34
|
+
- leveldb/db/db_impl.h
|
65
35
|
- leveldb/db/db_iter.cc
|
66
|
-
- leveldb/db/
|
67
|
-
- leveldb/db/
|
68
|
-
- leveldb/db/
|
69
|
-
- leveldb/db/
|
36
|
+
- leveldb/db/db_iter.h
|
37
|
+
- leveldb/db/db_test.cc
|
38
|
+
- leveldb/db/dbformat.cc
|
39
|
+
- leveldb/db/dbformat.h
|
40
|
+
- leveldb/db/dbformat_test.cc
|
41
|
+
- leveldb/db/filename.cc
|
42
|
+
- leveldb/db/filename.h
|
70
43
|
- leveldb/db/filename_test.cc
|
71
|
-
- leveldb/db/snapshot.h
|
72
|
-
- leveldb/db/log_reader.cc
|
73
44
|
- leveldb/db/log_format.h
|
74
|
-
- leveldb/db/
|
75
|
-
- leveldb/db/
|
76
|
-
- leveldb/db/
|
77
|
-
- leveldb/db/
|
78
|
-
- leveldb/db/
|
45
|
+
- leveldb/db/log_reader.cc
|
46
|
+
- leveldb/db/log_reader.h
|
47
|
+
- leveldb/db/log_test.cc
|
48
|
+
- leveldb/db/log_writer.cc
|
49
|
+
- leveldb/db/log_writer.h
|
50
|
+
- leveldb/db/memtable.cc
|
79
51
|
- leveldb/db/memtable.h
|
80
|
-
- leveldb/db/
|
81
|
-
- leveldb/db/
|
82
|
-
- leveldb/db/builder.cc
|
52
|
+
- leveldb/db/repair.cc
|
53
|
+
- leveldb/db/skiplist.h
|
83
54
|
- leveldb/db/skiplist_test.cc
|
84
|
-
- leveldb/db/
|
55
|
+
- leveldb/db/snapshot.h
|
56
|
+
- leveldb/db/table_cache.cc
|
57
|
+
- leveldb/db/table_cache.h
|
58
|
+
- leveldb/db/version_edit.cc
|
85
59
|
- leveldb/db/version_edit.h
|
86
|
-
- leveldb/db/
|
60
|
+
- leveldb/db/version_edit_test.cc
|
61
|
+
- leveldb/db/version_set.cc
|
62
|
+
- leveldb/db/version_set.h
|
63
|
+
- leveldb/db/write_batch.cc
|
64
|
+
- leveldb/db/write_batch_internal.h
|
65
|
+
- leveldb/db/write_batch_test.cc
|
66
|
+
- leveldb/include/leveldb/cache.h
|
87
67
|
- leveldb/include/leveldb/comparator.h
|
88
|
-
- leveldb/include/leveldb/
|
89
|
-
- leveldb/include/leveldb/
|
68
|
+
- leveldb/include/leveldb/db.h
|
69
|
+
- leveldb/include/leveldb/env.h
|
90
70
|
- leveldb/include/leveldb/iterator.h
|
71
|
+
- leveldb/include/leveldb/options.h
|
72
|
+
- leveldb/include/leveldb/slice.h
|
73
|
+
- leveldb/include/leveldb/status.h
|
74
|
+
- leveldb/include/leveldb/table.h
|
91
75
|
- leveldb/include/leveldb/table_builder.h
|
92
|
-
- leveldb/include/leveldb/env.h
|
93
|
-
- leveldb/include/leveldb/db.h
|
94
|
-
- leveldb/include/leveldb/cache.h
|
95
76
|
- leveldb/include/leveldb/write_batch.h
|
96
|
-
- leveldb/
|
97
|
-
- leveldb/
|
77
|
+
- leveldb/port/port.h
|
78
|
+
- leveldb/port/port_android.cc
|
79
|
+
- leveldb/port/port_android.h
|
80
|
+
- leveldb/port/port_chromium.cc
|
81
|
+
- leveldb/port/port_chromium.h
|
82
|
+
- leveldb/port/port_example.h
|
83
|
+
- leveldb/port/port_osx.cc
|
84
|
+
- leveldb/port/port_osx.h
|
85
|
+
- leveldb/port/port_posix.cc
|
86
|
+
- leveldb/port/port_posix.h
|
87
|
+
- leveldb/port/sha1_portable.cc
|
88
|
+
- leveldb/port/sha1_portable.h
|
89
|
+
- leveldb/port/sha1_test.cc
|
90
|
+
- leveldb/port/win/stdint.h
|
91
|
+
- leveldb/table/block.cc
|
98
92
|
- leveldb/table/block.h
|
93
|
+
- leveldb/table/block_builder.cc
|
94
|
+
- leveldb/table/block_builder.h
|
99
95
|
- leveldb/table/format.cc
|
100
|
-
- leveldb/table/
|
96
|
+
- leveldb/table/format.h
|
97
|
+
- leveldb/table/iterator.cc
|
101
98
|
- leveldb/table/iterator_wrapper.h
|
99
|
+
- leveldb/table/merger.cc
|
102
100
|
- leveldb/table/merger.h
|
103
|
-
- leveldb/table/iterator.cc
|
104
|
-
- leveldb/table/two_level_iterator.h
|
105
|
-
- leveldb/table/two_level_iterator.cc
|
106
|
-
- leveldb/table/format.h
|
107
101
|
- leveldb/table/table.cc
|
108
|
-
- leveldb/table/merger.cc
|
109
|
-
- leveldb/table/block_builder.h
|
110
|
-
- leveldb/table/block.cc
|
111
|
-
- leveldb/table/block_builder.cc
|
112
102
|
- leveldb/table/table_builder.cc
|
113
|
-
- leveldb/
|
114
|
-
- leveldb/
|
115
|
-
- leveldb/
|
116
|
-
- leveldb/util/
|
117
|
-
- leveldb/util/histogram.h
|
118
|
-
- leveldb/util/testutil.h
|
103
|
+
- leveldb/table/table_test.cc
|
104
|
+
- leveldb/table/two_level_iterator.cc
|
105
|
+
- leveldb/table/two_level_iterator.h
|
106
|
+
- leveldb/util/arena.cc
|
119
107
|
- leveldb/util/arena.h
|
120
|
-
- leveldb/util/cache_test.cc
|
121
108
|
- leveldb/util/arena_test.cc
|
122
|
-
- leveldb/util/
|
123
|
-
- leveldb/util/
|
124
|
-
- leveldb/util/
|
125
|
-
- leveldb/util/testharness.cc
|
109
|
+
- leveldb/util/cache.cc
|
110
|
+
- leveldb/util/cache_test.cc
|
111
|
+
- leveldb/util/coding.cc
|
126
112
|
- leveldb/util/coding.h
|
127
|
-
- leveldb/util/
|
128
|
-
- leveldb/util/
|
129
|
-
- leveldb/util/
|
130
|
-
- leveldb/util/hash.cc
|
113
|
+
- leveldb/util/coding_test.cc
|
114
|
+
- leveldb/util/comparator.cc
|
115
|
+
- leveldb/util/crc32c.cc
|
131
116
|
- leveldb/util/crc32c.h
|
132
|
-
- leveldb/util/
|
133
|
-
- leveldb/util/
|
117
|
+
- leveldb/util/crc32c_test.cc
|
118
|
+
- leveldb/util/env.cc
|
119
|
+
- leveldb/util/env_chromium.cc
|
134
120
|
- leveldb/util/env_posix.cc
|
135
|
-
- leveldb/util/
|
121
|
+
- leveldb/util/env_test.cc
|
122
|
+
- leveldb/util/hash.cc
|
123
|
+
- leveldb/util/hash.h
|
124
|
+
- leveldb/util/histogram.cc
|
125
|
+
- leveldb/util/histogram.h
|
126
|
+
- leveldb/util/logging.cc
|
127
|
+
- leveldb/util/logging.h
|
128
|
+
- leveldb/util/mutexlock.h
|
136
129
|
- leveldb/util/options.cc
|
137
130
|
- leveldb/util/random.h
|
138
|
-
- leveldb/util/logging.h
|
139
|
-
- leveldb/util/coding.cc
|
140
131
|
- leveldb/util/status.cc
|
141
|
-
- leveldb/util/
|
142
|
-
- leveldb/util/
|
132
|
+
- leveldb/util/testharness.cc
|
133
|
+
- leveldb/util/testharness.h
|
134
|
+
- leveldb/util/testutil.cc
|
135
|
+
- leveldb/util/testutil.h
|
143
136
|
has_rdoc: true
|
144
137
|
homepage: http://github.com/wmorgan/leveldb-ruby
|
145
138
|
licenses: []
|
146
|
-
|
147
139
|
post_install_message:
|
148
|
-
rdoc_options:
|
140
|
+
rdoc_options:
|
149
141
|
- -c
|
150
142
|
- utf8
|
151
143
|
- --main
|
152
144
|
- README
|
153
145
|
- --title
|
154
146
|
- LevelDB
|
155
|
-
require_paths:
|
147
|
+
require_paths:
|
156
148
|
- lib
|
157
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
150
|
none: false
|
159
|
-
requirements:
|
160
|
-
- -
|
161
|
-
- !ruby/object:Gem::Version
|
162
|
-
|
163
|
-
|
164
|
-
- 0
|
165
|
-
version: "0"
|
166
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ! '>='
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
156
|
none: false
|
168
|
-
requirements:
|
169
|
-
- -
|
170
|
-
- !ruby/object:Gem::Version
|
171
|
-
|
172
|
-
segments:
|
173
|
-
- 0
|
174
|
-
version: "0"
|
157
|
+
requirements:
|
158
|
+
- - ! '>='
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
175
161
|
requirements: []
|
176
|
-
|
177
162
|
rubyforge_project:
|
178
163
|
rubygems_version: 1.6.0
|
179
164
|
signing_key:
|
180
165
|
specification_version: 3
|
181
166
|
summary: a Ruby binding to LevelDB
|
182
167
|
test_files: []
|
183
|
-
|