Skip to content

Commit 7bedbb6

Browse files
committed
alpha bind
1 parent d1c7512 commit 7bedbb6

File tree

13 files changed

+15670
-0
lines changed

13 files changed

+15670
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
build

binding.gyp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"targets": [
3+
{
4+
"target_name": "addon",
5+
"sources": [ "src/addon.cc" ],
6+
"include_dirs": [
7+
"<!(node -p \"require('node-addon-api').include\")",
8+
"include/"
9+
],
10+
"libraries": [ "-L/usr/src/chdb-node-addon/lib", "-lchdb" ],
11+
"cflags!": [ "-fno-exceptions" ],
12+
"cflags_cc!": [ "-fno-exceptions" ],
13+
"defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ]
14+
}
15+
]
16+
}
17+

example.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const addon = require('.');
2+
var result = addon.Execute('SELECT version()', 'TabSeparated');
3+
console.log(result)

include/libchdb.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef CHDB_H
2+
#define CHDB_H
3+
4+
#include <string.h>
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif
9+
10+
struct local_result
11+
{
12+
char * buf;
13+
size_t len;
14+
void * _vec; // std::vector<char> *, for freeing
15+
};
16+
17+
const char* ares_query(const char* queryStr, const char* format);
18+
struct local_result* query_stable(int arg, char ** argv);
19+
struct local_result * queryToBuffer(const char *queryStr, const char *format);
20+
21+
#ifdef __cplusplus
22+
}
23+
#endif
24+
25+
#endif

include/napi-inl.deprecated.h

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
#ifndef SRC_NAPI_INL_DEPRECATED_H_
2+
#define SRC_NAPI_INL_DEPRECATED_H_
3+
4+
////////////////////////////////////////////////////////////////////////////////
5+
// PropertyDescriptor class
6+
////////////////////////////////////////////////////////////////////////////////
7+
8+
template <typename Getter>
9+
inline PropertyDescriptor
10+
PropertyDescriptor::Accessor(const char* utf8name,
11+
Getter getter,
12+
napi_property_attributes attributes,
13+
void* /*data*/) {
14+
using CbData = details::CallbackData<Getter, Napi::Value>;
15+
// TODO: Delete when the function is destroyed
16+
auto callbackData = new CbData({ getter, nullptr });
17+
18+
return PropertyDescriptor({
19+
utf8name,
20+
nullptr,
21+
nullptr,
22+
CbData::Wrapper,
23+
nullptr,
24+
nullptr,
25+
attributes,
26+
callbackData
27+
});
28+
}
29+
30+
template <typename Getter>
31+
inline PropertyDescriptor PropertyDescriptor::Accessor(const std::string& utf8name,
32+
Getter getter,
33+
napi_property_attributes attributes,
34+
void* data) {
35+
return Accessor(utf8name.c_str(), getter, attributes, data);
36+
}
37+
38+
template <typename Getter>
39+
inline PropertyDescriptor PropertyDescriptor::Accessor(napi_value name,
40+
Getter getter,
41+
napi_property_attributes attributes,
42+
void* /*data*/) {
43+
using CbData = details::CallbackData<Getter, Napi::Value>;
44+
// TODO: Delete when the function is destroyed
45+
auto callbackData = new CbData({ getter, nullptr });
46+
47+
return PropertyDescriptor({
48+
nullptr,
49+
name,
50+
nullptr,
51+
CbData::Wrapper,
52+
nullptr,
53+
nullptr,
54+
attributes,
55+
callbackData
56+
});
57+
}
58+
59+
template <typename Getter>
60+
inline PropertyDescriptor PropertyDescriptor::Accessor(Name name,
61+
Getter getter,
62+
napi_property_attributes attributes,
63+
void* data) {
64+
napi_value nameValue = name;
65+
return PropertyDescriptor::Accessor(nameValue, getter, attributes, data);
66+
}
67+
68+
template <typename Getter, typename Setter>
69+
inline PropertyDescriptor PropertyDescriptor::Accessor(const char* utf8name,
70+
Getter getter,
71+
Setter setter,
72+
napi_property_attributes attributes,
73+
void* /*data*/) {
74+
using CbData = details::AccessorCallbackData<Getter, Setter>;
75+
// TODO: Delete when the function is destroyed
76+
auto callbackData = new CbData({ getter, setter, nullptr });
77+
78+
return PropertyDescriptor({
79+
utf8name,
80+
nullptr,
81+
nullptr,
82+
CbData::GetterWrapper,
83+
CbData::SetterWrapper,
84+
nullptr,
85+
attributes,
86+
callbackData
87+
});
88+
}
89+
90+
template <typename Getter, typename Setter>
91+
inline PropertyDescriptor PropertyDescriptor::Accessor(const std::string& utf8name,
92+
Getter getter,
93+
Setter setter,
94+
napi_property_attributes attributes,
95+
void* data) {
96+
return Accessor(utf8name.c_str(), getter, setter, attributes, data);
97+
}
98+
99+
template <typename Getter, typename Setter>
100+
inline PropertyDescriptor PropertyDescriptor::Accessor(napi_value name,
101+
Getter getter,
102+
Setter setter,
103+
napi_property_attributes attributes,
104+
void* /*data*/) {
105+
using CbData = details::AccessorCallbackData<Getter, Setter>;
106+
// TODO: Delete when the function is destroyed
107+
auto callbackData = new CbData({ getter, setter, nullptr });
108+
109+
return PropertyDescriptor({
110+
nullptr,
111+
name,
112+
nullptr,
113+
CbData::GetterWrapper,
114+
CbData::SetterWrapper,
115+
nullptr,
116+
attributes,
117+
callbackData
118+
});
119+
}
120+
121+
template <typename Getter, typename Setter>
122+
inline PropertyDescriptor PropertyDescriptor::Accessor(Name name,
123+
Getter getter,
124+
Setter setter,
125+
napi_property_attributes attributes,
126+
void* data) {
127+
napi_value nameValue = name;
128+
return PropertyDescriptor::Accessor(nameValue, getter, setter, attributes, data);
129+
}
130+
131+
template <typename Callable>
132+
inline PropertyDescriptor PropertyDescriptor::Function(const char* utf8name,
133+
Callable cb,
134+
napi_property_attributes attributes,
135+
void* /*data*/) {
136+
using ReturnType = decltype(cb(CallbackInfo(nullptr, nullptr)));
137+
using CbData = details::CallbackData<Callable, ReturnType>;
138+
// TODO: Delete when the function is destroyed
139+
auto callbackData = new CbData({ cb, nullptr });
140+
141+
return PropertyDescriptor({
142+
utf8name,
143+
nullptr,
144+
CbData::Wrapper,
145+
nullptr,
146+
nullptr,
147+
nullptr,
148+
attributes,
149+
callbackData
150+
});
151+
}
152+
153+
template <typename Callable>
154+
inline PropertyDescriptor PropertyDescriptor::Function(const std::string& utf8name,
155+
Callable cb,
156+
napi_property_attributes attributes,
157+
void* data) {
158+
return Function(utf8name.c_str(), cb, attributes, data);
159+
}
160+
161+
template <typename Callable>
162+
inline PropertyDescriptor PropertyDescriptor::Function(napi_value name,
163+
Callable cb,
164+
napi_property_attributes attributes,
165+
void* /*data*/) {
166+
using ReturnType = decltype(cb(CallbackInfo(nullptr, nullptr)));
167+
using CbData = details::CallbackData<Callable, ReturnType>;
168+
// TODO: Delete when the function is destroyed
169+
auto callbackData = new CbData({ cb, nullptr });
170+
171+
return PropertyDescriptor({
172+
nullptr,
173+
name,
174+
CbData::Wrapper,
175+
nullptr,
176+
nullptr,
177+
nullptr,
178+
attributes,
179+
callbackData
180+
});
181+
}
182+
183+
template <typename Callable>
184+
inline PropertyDescriptor PropertyDescriptor::Function(Name name,
185+
Callable cb,
186+
napi_property_attributes attributes,
187+
void* data) {
188+
napi_value nameValue = name;
189+
return PropertyDescriptor::Function(nameValue, cb, attributes, data);
190+
}
191+
192+
#endif // !SRC_NAPI_INL_DEPRECATED_H_

0 commit comments

Comments
 (0)