Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,7 @@ lib-cov | |
pids | ||
logs | ||
results | ||
build/ | ||
node_modules/ | ||
|
||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
'targets': [ | ||
{ | ||
'target_name': 'sync', | ||
'sources': [ 'ext/sync.cc' ], | ||
'cflags!': [ '-fno-exceptions' ], | ||
'cflags_cc!': [ '-fno-exceptions' ], | ||
'conditions': [ | ||
['OS=="mac"', { | ||
'xcode_settings': { | ||
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES' | ||
} | ||
}] | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include <stdarg.h> | ||
#include <cstdlib> | ||
#include <cstring> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
|
||
#ifdef __clang__ | ||
#pragma clang diagnostic push | ||
#pragma clang diagnostic ignored "-Wunused-parameter" | ||
#endif | ||
|
||
#include <v8.h> | ||
|
||
// this and the above block must be around the v8.h header otherwise | ||
// v8 is not happy | ||
#ifdef __clang__ | ||
#pragma clang diagnostic pop | ||
#endif | ||
|
||
#include <node.h> | ||
#include <node_version.h> | ||
#include <node_buffer.h> | ||
|
||
#include <cmath> | ||
#include <iostream> | ||
#include <limits> | ||
#include <vector> | ||
|
||
#ifdef __sun | ||
#include <alloca.h> | ||
#endif | ||
|
||
#include "sync.h" | ||
|
||
using namespace v8; | ||
using namespace node; | ||
|
||
Persistent<FunctionTemplate> Sync::constructor_template; | ||
|
||
|
||
Sync::Sync() : ObjectWrap() { | ||
} | ||
|
||
void Sync::Initialize(v8::Handle<v8::Object> target) { | ||
// Grab the scope of the call from Node | ||
HandleScope scope; | ||
// Define a new function template | ||
Local<FunctionTemplate> t = FunctionTemplate::New(New); | ||
constructor_template = Persistent<FunctionTemplate>::New(t); | ||
constructor_template->InstanceTemplate()->SetInternalFieldCount(1); | ||
constructor_template->SetClassName(String::NewSymbol("Sync")); | ||
|
||
// Instance methods | ||
NODE_SET_PROTOTYPE_METHOD(constructor_template, "execute", Execute); | ||
|
||
// Set the class name | ||
target->ForceSet(String::NewSymbol("Sync"), constructor_template->GetFunction()); | ||
} | ||
|
||
// Create a new instance of BSON and passing it the existing context | ||
Handle<Value> Sync::New(const Arguments &args) { | ||
HandleScope scope; | ||
|
||
Sync *sync = new Sync(); | ||
sync->Wrap(args.This()); | ||
return args.This(); | ||
} | ||
|
||
Handle<Value> Sync::Execute(const Arguments &args) | ||
{ | ||
HandleScope scope; | ||
|
||
return scope.Close(Boolean::New(true)); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//=========================================================================== | ||
|
||
#ifndef SYNC_H_ | ||
#define SYNC_H_ | ||
|
||
//=========================================================================== | ||
|
||
#include <node.h> | ||
#include <node_object_wrap.h> | ||
#include <v8.h> | ||
|
||
using namespace v8; | ||
using namespace node; | ||
|
||
//=========================================================================== | ||
class Sync : public ObjectWrap { | ||
public: | ||
Sync(); | ||
~Sync() {} | ||
|
||
static void Initialize(Handle<Object> target); | ||
|
||
static Handle<Value> Execute(const Arguments &args); | ||
|
||
// Constructor used for creating new BSON objects from C++ | ||
static Persistent<FunctionTemplate> constructor_template; | ||
|
||
private: | ||
static Handle<Value> New(const Arguments &args); | ||
}; | ||
|
||
#endif // SYNC_H_ | ||
|
||
//=========================================================================== | ||
// Exporting function | ||
extern "C" void init(Handle<Object> target) | ||
{ | ||
HandleScope scope; | ||
Sync::Initialize(target); | ||
} | ||
|
||
NODE_MODULE(sync, Sync::Initialize); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
var ConsoleRepl = require("./lib/console_repl").ConsoleRepl; | ||
|
||
var options = { | ||
shell: false | ||
, nodb: false | ||
, norc: false | ||
, quiet: false | ||
, port: 27017 | ||
, host: "localhost" | ||
, eval: null | ||
, username: null | ||
, password: null | ||
, authenticationMechanism: null | ||
, help: false | ||
, version: false | ||
, verbose: false | ||
, ipv6: false | ||
, ssl: false | ||
, sslCAFile: null | ||
, sslPEMKeyFile: null | ||
, sslPEMKeyPassword: null | ||
} | ||
|
||
var console_repl = new ConsoleRepl(options); | ||
console_repl.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
var repl = require('repl') | ||
, format = require('util').format | ||
, MongoClient = require('mongodb').MongoClient | ||
, Db = require('./wrappers/db').Db | ||
, Sync = require('../build/Release/sync').Sync; | ||
|
||
console.dir(Sync); | ||
|
||
ConsoleRepl = function ConsoleRepl(options) { | ||
this.options = options; | ||
console.log("====================== create") | ||
this.sync = new Sync(); | ||
console.log("====================== create done") | ||
|
||
// Split out the db name if specified | ||
if(this.options.host.match(/\//) != null) { | ||
this.options.db_name = this.options.host.split(/\//)[1]; | ||
this.options.host = this.options.host.split(/\//)[0]; | ||
} else { | ||
this.options.db_name = "test"; | ||
} | ||
|
||
// Create connection url | ||
this.options.url = format("mongodb://%s:%s/%s" | ||
, this.options.host | ||
, this.options.port | ||
, this.options.db_name); | ||
|
||
// Global context | ||
this.global = global; | ||
} | ||
|
||
ConsoleRepl.prototype.start = function() { | ||
// Our script context | ||
var scope = {}; | ||
var self = this; | ||
// console.dir(this.options) | ||
|
||
console.log("MongoDB shell version: 0.0.1 - node"); | ||
console.log(format("connecting to %s", this.options.db_name)); | ||
|
||
MongoClient.connect(this.options.url, function(err, db) { | ||
if(err) throw err; | ||
|
||
// Our db command | ||
this.global.db = new Db(self.sync, db); | ||
|
||
repl.start({ | ||
prompt: ">" | ||
, global: true | ||
}) | ||
|
||
}); | ||
} | ||
|
||
exports.ConsoleRepl = ConsoleRepl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
var Db = function(sync, db) { | ||
this.sync = sync; | ||
this.db = db; | ||
} | ||
|
||
Db.prototype.runCommand = function(command) { | ||
var final_command = {}; | ||
if(typeof command == "string") { | ||
final_command = {}; | ||
final_command[command] = true; | ||
} else { | ||
final_command = command; | ||
} | ||
|
||
console.log("=============================== running command") | ||
console.dir(final_command) | ||
|
||
// Execute the db command in sync mode | ||
var result = this.sync.execute(db.executeDbCommand, final_command); | ||
} | ||
|
||
exports.Db = Db; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "repl", | ||
"version": "0.0.0", | ||
"description": "repl ====", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/christkv/repl.git" | ||
}, | ||
"dependencies": { | ||
"mongodb": "latest" | ||
, "exec-sync": "latest" | ||
}, | ||
"author": "", | ||
"license": "BSD", | ||
"readmeFilename": "README.md", | ||
"gitHead": "482845406fe069985937650a64026f7cd3fbfafa" | ||
} |