Skip to content

Commit

Permalink
Move from duckdb_web_pending_query_start to duckdb_web_pending_query_…
Browse files Browse the repository at this point in the history
…start_buffer
  • Loading branch information
carlopi committed Oct 30, 2024
1 parent e89d2d7 commit feb1aba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ if(EMSCRIPTEN)
_duckdb_web_pending_query_cancel, \
_duckdb_web_pending_query_poll, \
_duckdb_web_pending_query_start, \
_duckdb_web_pending_query_start_buffer, \
_duckdb_web_prepared_close, \
_duckdb_web_prepared_create, \
_duckdb_web_prepared_run, \
Expand Down
8 changes: 8 additions & 0 deletions lib/src/webdb_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ void duckdb_web_pending_query_start(WASMResponse* packed, ConnectionHdl connHdl,
auto r = c->PendingQuery(script, allow_stream_result);
WASMResponseBuffer::Get().Store(*packed, std::move(r));
}
/// Start a pending query
void duckdb_web_pending_query_start_buffer(WASMResponse* packed, ConnectionHdl connHdl, const uint8_t* buffer,
size_t buffer_length, bool allow_stream_result) {
auto c = reinterpret_cast<WebDB::Connection*>(connHdl);
std::string_view S(reinterpret_cast<const char*>(buffer), buffer_length);
auto r = c->PendingQuery(S, allow_stream_result);
WASMResponseBuffer::Get().Store(*packed, std::move(r));
}
/// Poll a pending query
void duckdb_web_pending_query_poll(WASMResponse* packed, ConnectionHdl connHdl, const char* script) {
auto c = reinterpret_cast<WebDB::Connection*>(connHdl);
Expand Down
14 changes: 8 additions & 6 deletions packages/duckdb-wasm/src/bindings/bindings_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,21 @@ export abstract class DuckDBBindingsBase implements DuckDBBindings {
* Results can then be fetched using `fetchQueryResults`
*/
public startPendingQuery(conn: number, text: string, allowStreamResult: boolean = false): Uint8Array | null {
const [s, d, n] = callSRet(
this.mod,
'duckdb_web_pending_query_start',
['number', 'string', 'boolean'],
[conn, text, allowStreamResult],
);
const BUF = TEXT_ENCODER.encode(text);
const bufferPtr = this.mod._malloc(BUF.length );
const bufferOfs = this.mod.HEAPU8.subarray(bufferPtr, bufferPtr + BUF.length );
bufferOfs.set(BUF);
const [s, d, n] = callSRet(this.mod, 'duckdb_web_pending_query_start_buffer', ['number', 'number', 'number', 'boolean'], [conn, bufferPtr, BUF.length, allowStreamResult]);
if (s !== StatusCode.SUCCESS) {
this.mod._free(bufferPtr);
throw new Error(readString(this.mod, d, n));
}
if (d == 0) {
this.mod._free(bufferPtr);
return null;
}
const res = copyBuffer(this.mod, d, n);
this.mod._free(bufferPtr);
dropResponseBuffers(this.mod);
return res;
}
Expand Down

0 comments on commit feb1aba

Please sign in to comment.