[Pkg-javascript-commits] [node-leveldown] 283/492: added leveldb.destroy() implementation
Andrew Kelley
andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:14:09 UTC 2014
This is an automated email from the git hooks/post-receive script.
andrewrk-guest pushed a commit to annotated tag rocksdb-0.10.1
in repository node-leveldown.
commit 1db34b9026d0451d5c67d8431ccc00a6a0be4ee7
Author: Rod Vagg <rod at vagg.org>
Date: Sun Mar 24 22:51:46 2013 +1100
added leveldb.destroy() implementation
---
binding.gyp | 1 +
src/async.h | 3 ++-
src/leveldown.cc | 44 ++++++++++++++++++++++++++++++++++++++++++--
src/leveldown_async.cc | 31 +++++++++++++++++++++++++++++++
src/leveldown_async.h | 31 +++++++++++++++++++++++++++++++
5 files changed, 107 insertions(+), 3 deletions(-)
diff --git a/binding.gyp b/binding.gyp
index 99ab807..f9e2057 100644
--- a/binding.gyp
+++ b/binding.gyp
@@ -28,6 +28,7 @@
, "src/iterator.cc"
, "src/iterator_async.cc"
, "src/leveldown.cc"
+ , "src/leveldown_async.cc"
]
}]
}
\ No newline at end of file
diff --git a/src/async.h b/src/async.h
index 65c16cf..dc1b1e6 100644
--- a/src/async.h
+++ b/src/async.h
@@ -7,13 +7,14 @@
#define LD_ASYNC_H
#include <node.h>
+#include "database.h"
namespace leveldown {
/* abstract */ class AsyncWorker {
public:
AsyncWorker (
- Database* database
+ leveldown::Database* database
, v8::Persistent<v8::Function> callback
);
diff --git a/src/leveldown.cc b/src/leveldown.cc
index 2021e17..6370906 100644
--- a/src/leveldown.cc
+++ b/src/leveldown.cc
@@ -9,16 +9,56 @@
#include "database.h"
#include "iterator.h"
#include "batch.h"
+#include "leveldown_async.h"
namespace leveldown {
+v8::Handle<v8::Value> DestroyDB (const v8::Arguments& args) {
+ v8::HandleScope scope;
+
+ if (args.Length() < 2) {
+ LD_THROW_RETURN(destroy() requires `location` and `callback` arguments)
+ }
+
+ if (!args[0]->IsString()) {
+ LD_THROW_RETURN(leveldown() requires a location string argument)
+ }
+
+ if (!args[1]->IsFunction()) {
+ LD_THROW_RETURN(leveldown() requires a callback function argument)
+ }
+
+ LD_FROM_V8_STRING(location, v8::Handle<v8::String>::Cast(args[0]))
+
+ v8::Persistent<v8::Function> callback = v8::Persistent<v8::Function>::New(
+ LD_NODE_ISOLATE_PRE
+ v8::Local<v8::Function>::Cast(args[1])
+ );
+
+ DestroyWorker* worker = new DestroyWorker(
+ location
+ , callback
+ );
+
+ AsyncQueueWorker(worker);
+
+ return scope.Close(v8::Undefined());
+}
+
void Init (v8::Handle<v8::Object> target) {
Database::Init();
leveldown::Iterator::Init();
leveldown::Batch::Init();
- target->Set(v8::String::NewSymbol("leveldown")
- , v8::FunctionTemplate::New(LevelDOWN)->GetFunction());
+ v8::Local<v8::Function> leveldown =
+ v8::FunctionTemplate::New(LevelDOWN)->GetFunction();
+
+ leveldown->Set(
+ v8::String::NewSymbol("destroy")
+ , v8::FunctionTemplate::New(DestroyDB)->GetFunction()
+ );
+
+ target->Set(v8::String::NewSymbol("leveldown"), leveldown);
}
NODE_MODULE(leveldown, Init)
diff --git a/src/leveldown_async.cc b/src/leveldown_async.cc
new file mode 100644
index 0000000..4bdae6f
--- /dev/null
+++ b/src/leveldown_async.cc
@@ -0,0 +1,31 @@
+/* Copyright (c) 2012-2013 LevelDOWN contributors
+ * See list at <https://github.com/rvagg/node-leveldown#contributing>
+ * MIT +no-false-attribs License <https://github.com/rvagg/node-leveldown/blob/master/LICENSE>
+ */
+
+#include <leveldb/db.h>
+
+#include "leveldown.h"
+#include "leveldown_async.h"
+
+namespace leveldown {
+
+/** DESTROY WORKER **/
+
+DestroyWorker::DestroyWorker (
+ char* location
+ , v8::Persistent<v8::Function> callback
+) : AsyncWorker(NULL, callback)
+ , location(location)
+{};
+
+DestroyWorker::~DestroyWorker () {
+ delete location;
+}
+
+void DestroyWorker::Execute () {
+ leveldb::Options options;
+ status = leveldb::DestroyDB(location, options);
+}
+
+} // namespace leveldown
diff --git a/src/leveldown_async.h b/src/leveldown_async.h
new file mode 100644
index 0000000..d860f51
--- /dev/null
+++ b/src/leveldown_async.h
@@ -0,0 +1,31 @@
+/* Copyright (c) 2012-2013 LevelDOWN contributors
+ * See list at <https://github.com/rvagg/node-leveldown#contributing>
+ * MIT +no-false-attribs License <https://github.com/rvagg/node-leveldown/blob/master/LICENSE>
+ */
+
+#ifndef LD_LEVELDOWN_ASYNC_H
+#define LD_LEVELDOWN_ASYNC_H
+
+#include <node.h>
+
+#include "async.h"
+
+namespace leveldown {
+
+class DestroyWorker : public AsyncWorker {
+public:
+ DestroyWorker (
+ char* location
+ , v8::Persistent<v8::Function> callback
+ );
+
+ virtual ~DestroyWorker ();
+ virtual void Execute ();
+
+private:
+ char* location;
+};
+
+} // namespace leveldown
+
+#endif
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-leveldown.git
More information about the Pkg-javascript-commits
mailing list