nodejs-db-informix  master
nodejs bindings for Informix
 All Classes Functions Pages
informix.cxx
1 #include "informix.h"
2 
3 v8::Persistent<v8::FunctionTemplate> nodejs_db_informix::Informix::constructorTemplate;
4 
5 nodejs_db_informix::Informix::Informix(): nodejs_db::Binding() {
6  this->connection = new nodejs_db_informix::Connection();
7  assert(this->connection);
8 }
9 
10 
11 
12 nodejs_db_informix::Informix::~Informix() {
13  if (this->connection != NULL) {
14  delete this->connection;
15  }
16 }
17 
18 
19 
20 void nodejs_db_informix::Informix::Init(v8::Handle<v8::Object> exports) {
21  v8::HandleScope scope;
22 
23  v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(New);
24 
25  constructorTemplate = v8::Persistent<v8::FunctionTemplate>::New(t);
26  constructorTemplate->InstanceTemplate()->SetInternalFieldCount(1);
27 
28  nodejs_db::Binding::Init(exports, constructorTemplate);
29 
30  exports->Set(v8::String::NewSymbol("Informix")
31  , constructorTemplate->GetFunction());
32 }
33 
34 
35 
36 v8::Handle<v8::Value>
37 nodejs_db_informix::Informix::New(const v8::Arguments& args) {
38  v8::HandleScope scope;
39 
41  if (binding == NULL) {
42  THROW_EXCEPTION("Can't create client object")
43  }
44 
45  if (args.Length() > 0) {
46  ARG_CHECK_OBJECT(0, options);
47 
48  v8::Handle<v8::Value> set = binding->set(args[0]->ToObject());
49  if (!set.IsEmpty()) {
50  return scope.Close(set);
51  }
52  }
53 
54  binding->Wrap(args.This());
55 
56  return scope.Close(args.This());
57 }
58 
59 
60 
61 v8::Handle<v8::Value>
62 nodejs_db_informix::Informix::set(
63  const v8::Local<v8::Object> options
64 ) {
65  ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, hostname);
66  ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, user);
67  ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, password);
68  ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, database);
69  ARG_CHECK_OBJECT_ATTR_OPTIONAL_UINT32(options, port);
70  ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, charset);
71  ARG_CHECK_OBJECT_ATTR_OPTIONAL_BOOL(options, compress);
72  ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, initCommand);
73  ARG_CHECK_OBJECT_ATTR_OPTIONAL_UINT32(options, readTimeout);
74  ARG_CHECK_OBJECT_ATTR_OPTIONAL_BOOL(options, reconnect);
75  ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, socket);
76  ARG_CHECK_OBJECT_ATTR_OPTIONAL_BOOL(options, sslVerifyServer);
77  ARG_CHECK_OBJECT_ATTR_OPTIONAL_UINT32(options, timeout);
78  ARG_CHECK_OBJECT_ATTR_OPTIONAL_UINT32(options, writeTimeout);
79 
80  // c is connection
82  static_cast<nodejs_db_informix::Connection*>(this->connection);
83 
84  v8::String::Utf8Value hostname(options->Get(hostname_key)->ToString());
85  v8::String::Utf8Value user(options->Get(user_key)->ToString());
86  v8::String::Utf8Value password(options->Get(password_key)->ToString());
87  v8::String::Utf8Value database(options->Get(database_key)->ToString());
88 
89  if (options->Has(hostname_key)) {
90  c->setHostname(*hostname);
91  }
92 
93  if (options->Has(user_key)) {
94  c->setUser(*user);
95  }
96 
97  if (options->Has(password_key)) {
98  c->setPassword(*password);
99  }
100 
101  if (options->Has(database_key)) {
102  c->setDatabase(*database);
103  }
104 
105  if (options->Has(port_key)) {
106  c->setPort(options->Get(port_key)->ToUint32()->Value());
107  }
108 
109  if (options->Has(charset_key)) {
110  v8::String::Utf8Value charset(options->Get(charset_key)->ToString());
111  c->setCharset(*charset);
112  }
113 
114  if (options->Has(compress_key)) {
115  c->setCompress(options->Get(compress_key)->IsTrue());
116  }
117 
118  if (options->Has(initCommand_key)) {
119  v8::String::Utf8Value initCommand(options->Get(initCommand_key)->ToString());
120  c->setInitCommand(*initCommand);
121  }
122 
123  if (options->Has(readTimeout_key)) {
124  c->setReadTimeout(options->Get(readTimeout_key)->ToUint32()->Value());
125  }
126 
127  if (options->Has(reconnect_key)) {
128  c->setReconnect(options->Get(reconnect_key)->IsTrue());
129  }
130 
131  if (options->Has(socket_key)) {
132  v8::String::Utf8Value socket(options->Get(socket_key)->ToString());
133  c->setSocket(*socket);
134  }
135 
136  if (options->Has(sslVerifyServer_key)) {
137  c->setSslVerifyServer(options->Get(sslVerifyServer_key)->IsTrue());
138  }
139 
140  if (options->Has(timeout_key)) {
141  c->setTimeout(options->Get(timeout_key)->ToUint32()->Value());
142  }
143 
144  if (options->Has(writeTimeout_key)) {
145  c->setWriteTimeout(options->Get(writeTimeout_key)->ToUint32()->Value());
146  }
147 
148  return v8::Handle<v8::Value>();
149 }
150 
151 
152 
153 v8::Persistent<v8::Object>
154 nodejs_db_informix::Informix::createQuery()
155 const {
156  v8::Persistent<v8::Object> query(
157  nodejs_db_informix::Query::constructorTemplate->GetFunction()->NewInstance());
158  return query;
159 }