-
Notifications
You must be signed in to change notification settings - Fork 1
/
parser.cc
46 lines (37 loc) · 1017 Bytes
/
parser.cc
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
#include <nan.h>
#include "pg_query.h"
using v8::FunctionTemplate;
using v8::Object;
using v8::String;
using Nan::GetFunction;
using Nan::New;
using Nan::Set;
using Nan::Utf8String;
using Nan::Error;
NAN_METHOD(parse) {
PgQueryParseResult result;
Utf8String query(info[0]);
result = pg_query_parse(*query);
if (result.error) {
info.GetReturnValue().Set(Error(result.error->message));
} else {
info.GetReturnValue().Set(New(result.parse_tree).ToLocalChecked());
}
pg_query_free_parse_result(result);
}
NAN_METHOD(parse_plpgsql) {
PgQueryPlpgsqlParseResult result;
Utf8String query(info[0]);
result = pg_query_parse_plpgsql(*query);
if (result.error) {
info.GetReturnValue().Set(Error(result.error->message));
} else {
info.GetReturnValue().Set(New(result.plpgsql_funcs).ToLocalChecked());
}
pg_query_free_plpgsql_parse_result(result);
}
NAN_MODULE_INIT(InitAll) {
NAN_EXPORT(target, parse);
NAN_EXPORT(target, parse_plpgsql);
}
NODE_MODULE(parser, InitAll)