duckdb 0.4.1-dev1057.0 → 0.4.1-dev1060.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.
- package/lib/duckdb.js +25 -0
- package/package.json +1 -1
- package/src/database.cpp +1 -3
- package/src/duckdb.hpp +2 -2
- package/src/duckdb_node.cpp +1 -0
- package/src/duckdb_node.hpp +34 -1
- package/src/parquet-amalgamation.cpp +37359 -37359
- package/src/statement.cpp +114 -7
- package/test/query_result.test.js +23 -0
package/lib/duckdb.js
CHANGED
|
@@ -6,6 +6,23 @@ module.exports = exports = duckdb;
|
|
|
6
6
|
var Database = duckdb.Database;
|
|
7
7
|
var Connection = duckdb.Connection;
|
|
8
8
|
var Statement = duckdb.Statement;
|
|
9
|
+
var QueryResult = duckdb.QueryResult;
|
|
10
|
+
|
|
11
|
+
QueryResult.prototype[Symbol.asyncIterator] = async function*() {
|
|
12
|
+
let prefetch = this.nextChunk();
|
|
13
|
+
while (true) {
|
|
14
|
+
const chunk = await prefetch;
|
|
15
|
+
// Null chunk indicates end of stream
|
|
16
|
+
if (!chunk) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
// Prefetch the next chunk while we're iterating
|
|
20
|
+
prefetch = this.nextChunk();
|
|
21
|
+
for (const row of chunk) {
|
|
22
|
+
yield row;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
9
26
|
|
|
10
27
|
|
|
11
28
|
Connection.prototype.run = function(sql) {
|
|
@@ -23,6 +40,14 @@ Connection.prototype.each = function(sql) {
|
|
|
23
40
|
return statement.each.apply(statement, arguments);
|
|
24
41
|
}
|
|
25
42
|
|
|
43
|
+
Connection.prototype.stream = async function*(sql) {
|
|
44
|
+
const statement = new Statement(this, sql);
|
|
45
|
+
const queryResult = await statement.stream.apply(statement, arguments);
|
|
46
|
+
for await (const result of queryResult) {
|
|
47
|
+
yield result;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
26
51
|
// this follows the wasm udfs somewhat but is simpler because we can pass data much more cleanly
|
|
27
52
|
Connection.prototype.register = function(name, return_type, fun) {
|
|
28
53
|
// TODO what if this throws an error somewhere? do we need a try/catch?
|
package/package.json
CHANGED
package/src/database.cpp
CHANGED
|
@@ -141,9 +141,7 @@ static void TaskExecuteCallback(napi_env e, void *data) {
|
|
|
141
141
|
static void TaskCompleteCallback(napi_env e, napi_status status, void *data) {
|
|
142
142
|
std::unique_ptr<TaskHolder> holder((TaskHolder *)data);
|
|
143
143
|
holder->db->TaskComplete(e);
|
|
144
|
-
|
|
145
|
-
holder->task->Callback();
|
|
146
|
-
}
|
|
144
|
+
holder->task->DoCallback();
|
|
147
145
|
}
|
|
148
146
|
|
|
149
147
|
void Database::TaskComplete(Napi::Env env) {
|
package/src/duckdb.hpp
CHANGED
|
@@ -11,8 +11,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
11
11
|
#pragma once
|
|
12
12
|
#define DUCKDB_AMALGAMATION 1
|
|
13
13
|
#define DUCKDB_AMALGAMATION_EXTENDED 1
|
|
14
|
-
#define DUCKDB_SOURCE_ID "
|
|
15
|
-
#define DUCKDB_VERSION "v0.4.1-
|
|
14
|
+
#define DUCKDB_SOURCE_ID "f2801e48b"
|
|
15
|
+
#define DUCKDB_VERSION "v0.4.1-dev1060"
|
|
16
16
|
//===----------------------------------------------------------------------===//
|
|
17
17
|
// DuckDB
|
|
18
18
|
//
|
package/src/duckdb_node.cpp
CHANGED
|
@@ -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(
|
package/src/duckdb_node.hpp
CHANGED
|
@@ -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;
|