Skip to content

Commit

Permalink
Merge pull request #7 from chdb-io/mac_loader_path
Browse files Browse the repository at this point in the history
Fix macOS loader path
  • Loading branch information
auxten committed Jan 3, 2024
2 parents 7780ec5 + 847c620 commit 941ef91
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 28 deletions.
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

0 comments on commit 941ef91

Please sign in to comment.