duckdb 0.4.1-dev182.0 → 0.4.1-dev1896.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);
@@ -41,6 +59,7 @@ class Connection;
41
59
  class Database : public Napi::ObjectWrap<Database> {
42
60
  public:
43
61
  explicit Database(const Napi::CallbackInfo &info);
62
+ ~Database() override;
44
63
  static Napi::Object Init(Napi::Env env, Napi::Object exports);
45
64
  void Process(Napi::Env env);
46
65
  void TaskComplete(Napi::Env env);
@@ -76,6 +95,8 @@ private:
76
95
  std::mutex task_mutex;
77
96
  bool task_inflight;
78
97
  static Napi::FunctionReference constructor;
98
+ Napi::Env env;
99
+ int64_t bytes_allocated = 0;
79
100
  };
80
101
 
81
102
  struct JSArgs;
@@ -127,8 +148,8 @@ public:
127
148
  Napi::Value All(const Napi::CallbackInfo &info);
128
149
  Napi::Value Each(const Napi::CallbackInfo &info);
129
150
  Napi::Value Run(const Napi::CallbackInfo &info);
130
- Napi::Value Bind(const Napi::CallbackInfo &info);
131
151
  Napi::Value Finish(const Napi::CallbackInfo &info);
152
+ Napi::Value Stream(const Napi::CallbackInfo &info);
132
153
 
133
154
  public:
134
155
  static Napi::FunctionReference constructor;
@@ -141,6 +162,21 @@ private:
141
162
  std::unique_ptr<StatementParam> HandleArgs(const Napi::CallbackInfo &info);
142
163
  };
143
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
+
144
180
  struct TaskHolder {
145
181
  std::unique_ptr<Task> task;
146
182
  napi_async_work request;