Skip to content

Commit

Permalink
Merge pull request #127 from belgattitude/fix-issue-with-node-file-tr…
Browse files Browse the repository at this point in the history
…acer

feat: explicit loading of native binaries
  • Loading branch information
jraymakers authored Jan 30, 2025
2 parents 9f684d8 + edac1a8 commit 1cac29e
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion bindings/pkgs/@duckdb/node-bindings/duckdb.js
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
module.exports = require(`@duckdb/node-bindings-${process.platform}-${process.arch}/duckdb.node`);
const getRuntimePlatformArch = () => `${process.platform}-${process.arch}`;

/**
* @throw Error if there isn't any available native binding for the current platform/arch.
*/
const getNativeNodeBinding = (runtimePlatformArch) => {
switch(runtimePlatformArch) {
case `linux-x64`:
return require('@duckdb/node-bindings-linux-x64/duckdb.node');
case 'linux-arm64':
return require('@duckdb/node-bindings-linux-arm64/duckdb.node');
case 'darwin-arm64':
return require('@duckdb/node-bindings-darwin-arm64/duckdb.node');
case 'darwin-x64':
return require('@duckdb/node-bindings-darwin-x64/duckdb.node');
case 'win32-x64':
return require('@duckdb/node-bindings-win32-x64/duckdb.node');
default:
const [platform, arch] = runtimePlatformArch.split('-')
throw new Error(`Error loading duckdb native binding: unsupported arch '${arch}' for platform '${platform}'`);
}
}

module.exports = getNativeNodeBinding(getRuntimePlatformArch());

0 comments on commit 1cac29e

Please sign in to comment.