forked from mariano/node-db
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.h
93 lines (85 loc) · 3.67 KB
/
query.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2011 Mariano Iglesias <[email protected]>
#ifndef QUERY_H_
#define QUERY_H_
#include <v8.h>
#include <stdlib.h>
#include <node.h>
#include <node_buffer.h>
#include <node_version.h>
#include <algorithm>
#include <cctype>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include "./node_defs.h"
#include "./connection.h"
#include "./events.h"
#include "./exception.h"
#include "./result.h"
namespace node_db {
class Query : public EventEmitter {
public:
static void Init(v8::Handle<v8::Object> target, v8::Persistent<v8::FunctionTemplate> constructorTemplate);
void setConnection(Connection* connection);
v8::Handle<v8::Value> set(const v8::Arguments& args);
protected:
struct row_t {
char** columns;
unsigned long* columnLengths;
};
struct execute_request_t {
v8::Persistent<v8::Object> context;
Query* query;
Result* result;
std::string* error;
uint16_t columnCount;
bool buffered;
std::vector<row_t*>* rows;
};
Connection* connection;
std::ostringstream sql;
std::vector< v8::Persistent<v8::Value> > values;
bool async;
bool cast;
bool bufferText;
v8::Persistent<v8::Function>* cbStart;
v8::Persistent<v8::Function>* cbExecute;
v8::Persistent<v8::Function>* cbFinish;
Query();
~Query();
static v8::Handle<v8::Value> Select(const v8::Arguments& args);
static v8::Handle<v8::Value> From(const v8::Arguments& args);
static v8::Handle<v8::Value> Join(const v8::Arguments& args);
static v8::Handle<v8::Value> Where(const v8::Arguments& args);
static v8::Handle<v8::Value> And(const v8::Arguments& args);
static v8::Handle<v8::Value> Or(const v8::Arguments& args);
static v8::Handle<v8::Value> Order(const v8::Arguments& args);
static v8::Handle<v8::Value> Limit(const v8::Arguments& args);
static v8::Handle<v8::Value> Add(const v8::Arguments& args);
static v8::Handle<v8::Value> Insert(const v8::Arguments& args);
static v8::Handle<v8::Value> Update(const v8::Arguments& args);
static v8::Handle<v8::Value> Set(const v8::Arguments& args);
static v8::Handle<v8::Value> Delete(const v8::Arguments& args);
static v8::Handle<v8::Value> Sql(const v8::Arguments& args);
static v8::Handle<v8::Value> Execute(const v8::Arguments& args);
static uv_async_t g_async;
static void uvExecute(uv_work_t* uvRequest);
static void uvExecuteFinished(uv_work_t* uvRequest);
void executeAsync(execute_request_t* request);
static void freeRequest(execute_request_t* request, bool freeAll = true);
std::string fieldName(v8::Local<v8::Value> value) const throw(Exception&);
std::string tableName(v8::Local<v8::Value> value, bool escape = true) const throw(Exception&);
v8::Handle<v8::Value> addCondition(const v8::Arguments& args, const char* separator);
v8::Local<v8::Object> row(Result* result, row_t* currentRow) const;
virtual std::string parseQuery() const throw(Exception&);
virtual std::vector<std::string::size_type> placeholders(std::string* parsed) const throw(Exception&);
virtual Result* execute() const throw(Exception&);
std::string value(v8::Local<v8::Value> value, bool inArray = false, bool escape = true, int precision = -1) const throw(Exception&);
private:
static bool gmtDeltaLoaded;
static int gmtDelta;
std::string fromDate(const double timeStamp) const throw(Exception&);
};
}
#endif // QUERY_H_