Skip to content

Commit

Permalink
Fix Node.js extension loading on Linux (#2899)
Browse files Browse the repository at this point in the history
  • Loading branch information
mewim committed Feb 16, 2024
1 parent f1296d5 commit 38cc747
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tools/nodejs_api/src_js/connection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

const KuzuNative = require("./kuzujs.node");
const KuzuNative = require("./kuzu_native.js");
const QueryResult = require("./query_result.js");
const PreparedStatement = require("./prepared_statement.js");

Expand Down
2 changes: 1 addition & 1 deletion tools/nodejs_api/src_js/database.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

const KuzuNative = require("./kuzujs.node");
const KuzuNative = require("./kuzu_native.js");
const LoggingLevel = require("./logging_level.js");

class Database {
Expand Down
25 changes: 25 additions & 0 deletions tools/nodejs_api/src_js/kuzu_native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* This file is a customized loader for the kuzujs.node native module.
* It is used to load the native module with the correct flags on Linux so that
* extension loading works correctly.
* @module kuzu_native
* @private
*/

const process = require("process");
const constants = require("constants");
const join = require("path").join;

const kuzuNativeModule = { exports: {} };
const modulePath = join(__dirname, "kuzujs.node");
if (process.platform === "linux") {
process.dlopen(
kuzuNativeModule,
modulePath,
constants.RTLD_LAZY | constants.RTLD_GLOBAL
);
} else {
process.dlopen(kuzuNativeModule, modulePath);
}

module.exports = kuzuNativeModule.exports;
4 changes: 2 additions & 2 deletions tools/nodejs_api/test/test_extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const { assert } = require("chai");

describe("Extension loading", () => {
it("should install and load httpfs extension", async function () {
this.timeout(10000);
await conn.query("INSTALL httpfs");
// Skip this test until the fix is in place
// await conn.query("LOAD EXTENSION httpfs");
await conn.query("LOAD EXTENSION httpfs");
});
});

0 comments on commit 38cc747

Please sign in to comment.