File tree Expand file tree Collapse file tree 4 files changed +31
-1
lines changed Expand file tree Collapse file tree 4 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,14 @@ node_db_mysql::Connection::~Connection() {
17
17
}
18
18
}
19
19
20
+ void node_db_mysql::Connection::setSocket (const std::string& socket) {
21
+ this ->socket = socket;
22
+ }
23
+
24
+ std::string node_db_mysql::Connection::getSocket () const {
25
+ return this ->socket ;
26
+ }
27
+
20
28
void node_db_mysql::Connection::open () throw(node_db::Exception&) {
21
29
this ->close ();
22
30
@@ -27,7 +35,7 @@ void node_db_mysql::Connection::open() throw(node_db::Exception&) {
27
35
this ->password .c_str (),
28
36
this ->database .c_str (),
29
37
this ->port ,
30
- NULL ,
38
+ ! this -> socket . empty () ? this -> socket . c_str () : NULL ,
31
39
0 );
32
40
if (!this ->opened ) {
33
41
throw node_db::Exception (mysql_error (this ->connection ));
Original file line number Diff line number Diff line change @@ -12,12 +12,17 @@ class Connection : public node_db::Connection {
12
12
public:
13
13
Connection ();
14
14
~Connection ();
15
+ std::string getSocket () const ;
16
+ void setSocket (const std::string& user);
15
17
void open () throw(node_db::Exception&);
16
18
void close ();
17
19
std::string escape (const std::string& string) const throw(node_db::Exception&);
18
20
std::string version () const ;
19
21
node_db::Result* query (const std::string& query) const throw(node_db::Exception&);
20
22
23
+ protected:
24
+ std::string socket;
25
+
21
26
private:
22
27
MYSQL* connection;
23
28
};
Original file line number Diff line number Diff line change @@ -48,6 +48,22 @@ v8::Handle<v8::Value> node_db_mysql::Mysql::New(const v8::Arguments& args) {
48
48
return scope.Close (args.This ());
49
49
}
50
50
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
+ ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING (options, socket);
56
+
57
+ node_db_mysql::Connection* connection = static_cast <node_db_mysql::Connection*>(this ->connection );
58
+
59
+ if (options->Has (socket_key)) {
60
+ v8::String::Utf8Value socket (options->Get (socket_key)->ToString ());
61
+ connection->setSocket (*socket);
62
+ }
63
+
64
+ return result;
65
+ }
66
+
51
67
v8::Persistent<v8::Object> node_db_mysql::Mysql::createQuery () const {
52
68
v8::Persistent<v8::Object> query (
53
69
node_db_mysql::Query::constructorTemplate->GetFunction ()->NewInstance ());
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ class Mysql : public node_db::Binding {
18
18
Mysql ();
19
19
~Mysql ();
20
20
static v8::Handle<v8::Value> New (const v8::Arguments& args);
21
+ v8::Handle<v8::Value> set (const v8::Arguments& args);
21
22
v8::Persistent<v8::Object> createQuery () const ;
22
23
};
23
24
}
You can’t perform that action at this time.
0 commit comments