Skip to content

Commit 941ef91

Browse files
authored
Merge pull request #7 from chdb-io/mac_loader_path
Fix macOS loader path
2 parents 7780ec5 + 847c620 commit 941ef91

File tree

5 files changed

+52
-28
lines changed

5 files changed

+52
-28
lines changed

README.md

+36-11
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,50 @@
11
<img src="https://avatars.githubusercontent.com/u/132536224" width=130 />
22

33
[![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)
4+
[![npm version](https://badge.fury.io/js/chdb.svg)](https://badge.fury.io/js/chdb)
45

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

8-
### Status
9+
### Install
910

10-
- Experimental bindings
11-
- Requires [`libchdb`](https://github.com/chdb-io/chdb) on the system
11+
```bash
12+
npm i chdb
13+
```
14+
15+
### Usage
16+
17+
```javascript
18+
const { query, Session } = require("chdb");
19+
20+
var ret;
21+
22+
// Test standalone query
23+
ret = query("SELECT version(), 'Hello chDB', chdb()", "CSV");
24+
console.log("Standalone Query Result:", ret);
25+
26+
// Test session query
27+
// Create a new session instance
28+
const session = new Session("./chdb-node-tmp");
29+
ret = session.query("SELECT 123", "CSV")
30+
console.log("Session Query Result:", ret);
31+
ret = session.query("CREATE DATABASE IF NOT EXISTS testdb;" +
32+
"CREATE TABLE IF NOT EXISTS testdb.testtable (id UInt32) ENGINE = MergeTree() ORDER BY id;");
33+
34+
session.query("USE testdb; INSERT INTO testtable VALUES (1), (2), (3);")
1235

13-
### Build
36+
ret = session.query("SELECT * FROM testtable;")
37+
console.log("Session Query Result:", ret);
38+
39+
// Clean up the session
40+
session.cleanup();
41+
42+
```
43+
44+
#### Build from source
1445

1546
```bash
1647
npm run libchdb
1748
npm install
1849
npm run test
1950
```
20-
21-
### Examples
22-
23-
See [example.js](example.js).
24-
25-

binding.gyp

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
{
2-
"variables": {
3-
"openssl_fips": "",
4-
},
52
"targets": [
63
{
74
"target_name": "chdb_node",
@@ -11,17 +8,9 @@
118
"."
129
],
1310
"libraries": [ "<(module_root_dir)/libchdb.so" ],
14-
"conditions": [
15-
['OS=="mac"', {
16-
"ldflags": [
17-
"-Wl,-rpath,@loader_path/../../"
18-
]
19-
}]
20-
],
2111
"cflags!": [ "-fno-exceptions" ],
2212
"cflags_cc!": [ "-fno-exceptions" ],
2313
"defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ]
2414
}
2515
]
26-
}
27-
16+
}

fix_loader_path.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
cd "$(dirname "$0")"
4+
5+
if [[ $(uname -s) == "Darwin" ]]; then
6+
install_name_tool -change libchdb.so @loader_path/../../libchdb.so build/Release/chdb_node.node
7+
otool -L build/Release/chdb_node.node
8+
fi

index.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
const chdbNode = require('./build/Release/chdb_node.node');
2-
const { mkdtempSync, rmdirSync } = require('fs');
1+
const path = require('path');
2+
const chdbNode = require(path.join(__dirname, 'build', 'Release', 'chdb_node.node'));
3+
const { mkdtempSync, rmSync } = require('fs');
34
const { join } = require('path');
45
const os = require('os');
56

@@ -31,7 +32,7 @@ class Session {
3132

3233
// Cleanup method to delete the temporary directory
3334
cleanup() {
34-
rmdirSync(this.path, { recursive: true });
35+
rmSync(this.path, { recursive: true }); // Replaced rmdirSync with rmSync
3536
}
3637
}
3738

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chdb",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "chDB bindings for nodejs",
55
"main": "index.js",
66
"repository": {
@@ -11,7 +11,8 @@
1111
"install": "npm run libchdb && npm run build",
1212
"test": "node example.js",
1313
"libchdb": "./update_libchdb.sh",
14-
"build": "node-gyp configure build"
14+
"fixloaderpath": "./fix_loader_path.sh",
15+
"build": "node-gyp configure build --verbose && npm run fixloaderpath"
1516
},
1617
"author": {
1718
"name": "chdb",

0 commit comments

Comments
 (0)