Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Moving option settings to driver
  • Loading branch information
mariano committed May 27, 2011
1 parent 1f14b08 commit ee8d442
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 45 deletions.
49 changes: 5 additions & 44 deletions binding.cc
Expand Up @@ -41,13 +41,15 @@ v8::Handle<v8::Value> node_db::Binding::Connect(const v8::Arguments& args) {
bool async = true;

if (args.Length() > 0) {
v8::Handle<v8::Value> set = binding->set(args);
ARG_CHECK_OBJECT(0, options);

v8::Local<v8::Object> options = args[0]->ToObject();

v8::Handle<v8::Value> set = binding->set(options);
if (!set.IsEmpty()) {
return scope.Close(set);
}

v8::Local<v8::Object> options = args[0]->ToObject();

ARG_CHECK_OBJECT_ATTR_OPTIONAL_BOOL(options, async);

if (options->Has(async_key) && options->Get(async_key)->IsFalse()) {
Expand Down Expand Up @@ -75,47 +77,6 @@ v8::Handle<v8::Value> node_db::Binding::Connect(const v8::Arguments& args) {
return scope.Close(v8::Undefined());
}

v8::Handle<v8::Value> node_db::Binding::set(const v8::Arguments& args) {
assert(this->connection);

ARG_CHECK_OBJECT(0, options);

v8::Local<v8::Object> options = args[0]->ToObject();

ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, hostname);
ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, user);
ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, password);
ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, database);
ARG_CHECK_OBJECT_ATTR_OPTIONAL_UINT32(options, port);

v8::String::Utf8Value hostname(options->Get(hostname_key)->ToString());
v8::String::Utf8Value user(options->Get(user_key)->ToString());
v8::String::Utf8Value password(options->Get(password_key)->ToString());
v8::String::Utf8Value database(options->Get(database_key)->ToString());

if (options->Has(hostname_key)) {
this->connection->setHostname(*hostname);
}

if (options->Has(user_key)) {
this->connection->setUser(*user);
}

if (options->Has(password_key)) {
this->connection->setPassword(*password);
}

if (options->Has(database_key)) {
this->connection->setDatabase(*database);
}

if (options->Has(port_key)) {
this->connection->setPort(options->Get(port_key)->ToInt32()->Value());
}

return v8::Handle<v8::Value>();
}

void node_db::Binding::connect(connect_request_t* request) {
try {
request->binding->connection->open();
Expand Down
2 changes: 1 addition & 1 deletion binding.h
Expand Up @@ -36,7 +36,7 @@ class Binding : public node::EventEmitter {
static void connect(connect_request_t* request);
static void connectFinished(connect_request_t* request);
static int eioConnectFinished(eio_req* eioRequest);
virtual v8::Handle<v8::Value> set(const v8::Arguments& args);
virtual v8::Handle<v8::Value> set(const v8::Local<v8::Object> options) = 0;
virtual v8::Persistent<v8::Object> createQuery() const = 0;
};
}
Expand Down

0 comments on commit ee8d442

Please sign in to comment.