Skip to content

Commit

Permalink
Merge pull request #7883 from Mause/bugfix/nodejs-http-state
Browse files Browse the repository at this point in the history
fix(nodejs): http state
  • Loading branch information
Mytherin committed Jun 11, 2023
2 parents b0a1a5a + f919df4 commit fd4cb74
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/client_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ shared_ptr<PreparedStatementData> ClientContext::CreatePreparedStatement(ClientC
planner.parameter_data.emplace_back(value);
}
}

client_data->http_state = make_shared<HTTPState>();
planner.CreatePlan(std::move(statement));
D_ASSERT(planner.plan || !planner.properties.bound_all_parameters);
profiler.EndPhase();
Expand Down
2 changes: 2 additions & 0 deletions tools/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
},
"devDependencies": {
"@types/chai": "^4.3.4",
"@types/chai-as-promised": "^7.1.5",
"@types/mocha": "^10.0.0",
"@types/node": "^18.11.0",
"apache-arrow": "^9.0.0",
"aws-sdk": "^2.790.0",
"chai": "^4.3.6",
"chai-as-promised": "^7.1.1",
"jsdoc3-parser": "^2.0.0",
"mocha": "^8.3.0",
"ts-node": "^10.9.1",
Expand Down
11 changes: 11 additions & 0 deletions tools/nodejs/test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import {Database, DuckDbError, HttpError, TableData} from '..';
import * as fs from 'fs';
import * as assert from 'assert';
import * as path from 'path';
import chaiAsPromised from 'chai-as-promised';
import chai, {expect} from "chai";

chai.use(chaiAsPromised);

const extension_base_path = "../../../build/release/extension";

Expand All @@ -26,6 +30,13 @@ function isHTTPException(err: DuckDbError): err is HttpError {

// Note: test will pass on http request failing due to connection issues.
const test_httpfs = async function (db: duckdb.Database) {
const promise = new Promise<void>((resolve, reject) =>
db.exec(`SELECT *
FROM parquet_scan('http://localhost:1234/whatever.parquet')`, function (err: DuckDbError | null) {
err ? reject(err) : resolve()
}));
await chai.assert.isRejected(promise, 'IO Error: Connection error for HTTP HEAD');

await new Promise<void>((resolve, reject) => db.all("SELECT id, first_name, last_name FROM PARQUET_SCAN('https://raw.githubusercontent.com/cwida/duckdb/master/data/parquet-testing/userdata1.parquet') LIMIT 3;", function (err: null | Error, rows: TableData) {
if (err) {
if (err.message.startsWith("Unable to connect to URL")) {
Expand Down

0 comments on commit fd4cb74

Please sign in to comment.