duckdb 0.4.1-dev958.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,6 +12,7 @@ Napi::Object RegisterModule(Napi::Env env, Napi::Object exports) {
12
12
  node_duckdb::Database::Init(env, exports);
13
13
  node_duckdb::Connection::Init(env, exports);
14
14
  node_duckdb::Statement::Init(env, exports);
15
+ node_duckdb::QueryResult::Init(env, exports);
15
16
 
16
17
  exports.DefineProperties({
17
18
  DEFINE_CONSTANT_INTEGER(exports, node_duckdb::Database::DUCKDB_NODEJS_ERROR, ERROR) DEFINE_CONSTANT_INTEGER(
@@ -15,8 +15,26 @@ struct Task {
15
15
  }
16
16
  object.Ref();
17
17
  }
18
+ explicit Task(Napi::Reference<Napi::Object> &object) : object(object) {
19
+ object.Ref();
20
+ }
21
+
22
+ // Called on a worker thread (i.e., not the main event loop thread)
18
23
  virtual void DoWork() = 0;
19
24
 
25
+ // Called on the event loop thread after the work has been completed. By
26
+ // default, call the associated callback, if defined. If you're writing
27
+ // a Task that uses promises, override this method instead of Callback.
28
+ virtual void DoCallback() {
29
+ auto env = object.Env();
30
+ Napi::HandleScope scope(env);
31
+
32
+ if (!callback.Value().IsUndefined()) {
33
+ Callback();
34
+ }
35
+ }
36
+
37
+ // Called on the event loop thread by DoCallback (see above)
20
38
  virtual void Callback() {
21
39
  auto env = object.Env();
22
40
  Napi::HandleScope scope(env);
@@ -130,8 +148,8 @@ public:
130
148
  Napi::Value All(const Napi::CallbackInfo &info);
131
149
  Napi::Value Each(const Napi::CallbackInfo &info);
132
150
  Napi::Value Run(const Napi::CallbackInfo &info);
133
- Napi::Value Bind(const Napi::CallbackInfo &info);
134
151
  Napi::Value Finish(const Napi::CallbackInfo &info);
152
+ Napi::Value Stream(const Napi::CallbackInfo &info);
135
153
 
136
154
  public:
137
155
  static Napi::FunctionReference constructor;
@@ -144,6 +162,21 @@ private:
144
162
  std::unique_ptr<StatementParam> HandleArgs(const Napi::CallbackInfo &info);
145
163
  };
146
164
 
165
+ class QueryResult : public Napi::ObjectWrap<QueryResult> {
166
+ public:
167
+ explicit QueryResult(const Napi::CallbackInfo &info);
168
+ ~QueryResult() override;
169
+ static Napi::Object Init(Napi::Env env, Napi::Object exports);
170
+ std::unique_ptr<duckdb::QueryResult> result;
171
+
172
+ public:
173
+ static Napi::FunctionReference constructor;
174
+ Napi::Value NextChunk(const Napi::CallbackInfo &info);
175
+
176
+ private:
177
+ Database *database_ref;
178
+ };
179
+
147
180
  struct TaskHolder {
148
181
  std::unique_ptr<Task> task;
149
182
  napi_async_work request;