Skip to content

Commit f58c4a2

Browse files
committed
Updating options processing since they are now moved to driver
1 parent 7752b58 commit f58c4a2

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/build/*
2-
/mysql-test.js
32
*.node
43
*.sh
54
*.swp

src/mysql.cc

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ v8::Handle<v8::Value> node_db_mysql::Mysql::New(const v8::Arguments& args) {
3737
}
3838

3939
if (args.Length() > 0) {
40-
v8::Handle<v8::Value> set = binding->set(args);
40+
ARG_CHECK_OBJECT(0, options);
41+
42+
v8::Handle<v8::Value> set = binding->set(args[0]->ToObject());
4143
if (!set.IsEmpty()) {
4244
return scope.Close(set);
4345
}
@@ -48,11 +50,12 @@ v8::Handle<v8::Value> node_db_mysql::Mysql::New(const v8::Arguments& args) {
4850
return scope.Close(args.This());
4951
}
5052

51-
v8::Handle<v8::Value> node_db_mysql::Mysql::set(const v8::Arguments& args) {
52-
v8::Handle<v8::Value> result = node_db::Binding::set(args);
53-
54-
v8::Local<v8::Object> options = args[0]->ToObject();
55-
53+
v8::Handle<v8::Value> node_db_mysql::Mysql::set(const v8::Local<v8::Object> options) {
54+
ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, hostname);
55+
ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, user);
56+
ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, password);
57+
ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, database);
58+
ARG_CHECK_OBJECT_ATTR_OPTIONAL_UINT32(options, port);
5659
ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, charset);
5760
ARG_CHECK_OBJECT_ATTR_OPTIONAL_BOOL(options, compress);
5861
ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, initCommand);
@@ -65,6 +68,31 @@ v8::Handle<v8::Value> node_db_mysql::Mysql::set(const v8::Arguments& args) {
6568

6669
node_db_mysql::Connection* connection = static_cast<node_db_mysql::Connection*>(this->connection);
6770

71+
v8::String::Utf8Value hostname(options->Get(hostname_key)->ToString());
72+
v8::String::Utf8Value user(options->Get(user_key)->ToString());
73+
v8::String::Utf8Value password(options->Get(password_key)->ToString());
74+
v8::String::Utf8Value database(options->Get(database_key)->ToString());
75+
76+
if (options->Has(hostname_key)) {
77+
connection->setHostname(*hostname);
78+
}
79+
80+
if (options->Has(user_key)) {
81+
connection->setUser(*user);
82+
}
83+
84+
if (options->Has(password_key)) {
85+
connection->setPassword(*password);
86+
}
87+
88+
if (options->Has(database_key)) {
89+
connection->setDatabase(*database);
90+
}
91+
92+
if (options->Has(port_key)) {
93+
connection->setPort(options->Get(port_key)->ToInt32()->Value());
94+
}
95+
6896
if (options->Has(charset_key)) {
6997
v8::String::Utf8Value charset(options->Get(charset_key)->ToString());
7098
connection->setCharset(*charset);
@@ -104,7 +132,7 @@ v8::Handle<v8::Value> node_db_mysql::Mysql::set(const v8::Arguments& args) {
104132
connection->setWriteTimeout(options->Get(writeTimeout_key)->ToInt32()->Value());
105133
}
106134

107-
return result;
135+
return v8::Handle<v8::Value>();
108136
}
109137

110138
v8::Persistent<v8::Object> node_db_mysql::Mysql::createQuery() const {

src/mysql.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Mysql : public node_db::Binding {
1818
Mysql();
1919
~Mysql();
2020
static v8::Handle<v8::Value> New(const v8::Arguments& args);
21-
v8::Handle<v8::Value> set(const v8::Arguments& args);
21+
v8::Handle<v8::Value> set(const v8::Local<v8::Object> options);
2222
v8::Persistent<v8::Object> createQuery() const;
2323
};
2424
}

0 commit comments

Comments
 (0)