Skip to content

Fix macOS loader path #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 36 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,50 @@
<img src="https://avatars.githubusercontent.com/u/132536224" width=130 />

[![chDB-node](https://github.com/chdb-io/chdb-node/actions/workflows/chdb-node-test.yml/badge.svg)](https://github.com/chdb-io/chdb-node/actions/workflows/chdb-node-test.yml)
[![npm version](https://badge.fury.io/js/chdb.svg)](https://badge.fury.io/js/chdb)

# chdb-node
[chDB](https://github.com/chdb-io/chdb) nodejs bindings for fun and hacking.
[chDB](https://github.com/chdb-io/chdb) nodejs bindings.

### Status
### Install

- Experimental bindings
- Requires [`libchdb`](https://github.com/chdb-io/chdb) on the system
```bash
npm i chdb
```

### Usage

```javascript
const { query, Session } = require("chdb");

var ret;

// Test standalone query
ret = query("SELECT version(), 'Hello chDB', chdb()", "CSV");
console.log("Standalone Query Result:", ret);

// Test session query
// Create a new session instance
const session = new Session("./chdb-node-tmp");
ret = session.query("SELECT 123", "CSV")
console.log("Session Query Result:", ret);
ret = session.query("CREATE DATABASE IF NOT EXISTS testdb;" +
"CREATE TABLE IF NOT EXISTS testdb.testtable (id UInt32) ENGINE = MergeTree() ORDER BY id;");

session.query("USE testdb; INSERT INTO testtable VALUES (1), (2), (3);")

### Build
ret = session.query("SELECT * FROM testtable;")
console.log("Session Query Result:", ret);

// Clean up the session
session.cleanup();

```

#### Build from source

```bash
npm run libchdb
npm install
npm run test
```

### Examples

See [example.js](example.js).


13 changes: 1 addition & 12 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"variables": {
"openssl_fips": "",
},
"targets": [
{
"target_name": "chdb_node",
Expand All @@ -11,17 +8,9 @@
"."
],
"libraries": [ "<(module_root_dir)/libchdb.so" ],
"conditions": [
['OS=="mac"', {
"ldflags": [
"-Wl,-rpath,@loader_path/../../"
]
}]
],
"cflags!": [ "-fno-exceptions" ],
"cflags_cc!": [ "-fno-exceptions" ],
"defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ]
}
]
}

}
8 changes: 8 additions & 0 deletions fix_loader_path.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

cd "$(dirname "$0")"

if [[ $(uname -s) == "Darwin" ]]; then
install_name_tool -change libchdb.so @loader_path/../../libchdb.so build/Release/chdb_node.node
otool -L build/Release/chdb_node.node
fi
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const chdbNode = require('./build/Release/chdb_node.node');
const { mkdtempSync, rmdirSync } = require('fs');
const path = require('path');
const chdbNode = require(path.join(__dirname, 'build', 'Release', 'chdb_node.node'));
const { mkdtempSync, rmSync } = require('fs');
const { join } = require('path');
const os = require('os');

Expand Down Expand Up @@ -31,7 +32,7 @@ class Session {

// Cleanup method to delete the temporary directory
cleanup() {
rmdirSync(this.path, { recursive: true });
rmSync(this.path, { recursive: true }); // Replaced rmdirSync with rmSync
}
}

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chdb",
"version": "1.1.1",
"version": "1.1.2",
"description": "chDB bindings for nodejs",
"main": "index.js",
"repository": {
Expand All @@ -11,7 +11,8 @@
"install": "npm run libchdb && npm run build",
"test": "node example.js",
"libchdb": "./update_libchdb.sh",
"build": "node-gyp configure build"
"fixloaderpath": "./fix_loader_path.sh",
"build": "node-gyp configure build --verbose && npm run fixloaderpath"
},
"author": {
"name": "chdb",
Expand Down