-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from chdb-io/latest
resync latest
- Loading branch information
Showing
7 changed files
with
95 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,13 @@ | ||
import { Execute } from '.'; | ||
import { db, chdb } from '.'; | ||
|
||
const conn = new db('CSV', '/tmp') | ||
var result; | ||
|
||
console.log(Execute("SELECT version()", "CSV")); | ||
// Test query | ||
result = conn.query("SELECT version()"); | ||
console.log(result) | ||
|
||
// Test session | ||
conn.session("CREATE FUNCTION IF NOT EXISTS hello AS () -> 'chDB'"); | ||
result = conn.session("SELECT hello()", "CSV"); | ||
console.log(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,35 @@ | ||
|
||
import { dlopen, FFIType, suffix, CString, ptr } from "bun:ffi"; | ||
|
||
const path = `lib/libchdb_bun.${suffix}`; | ||
|
||
const { symbols: chdb, } = dlopen(path, { | ||
Execute: { | ||
args: [FFIType.cstring, FFIType.cstring], | ||
returns:FFIType.cstring, | ||
}, | ||
ExecuteSession: { | ||
args: [FFIType.cstring, FFIType.cstring, FFIType.cstring], | ||
returns:FFIType.cstring, | ||
}, | ||
}, | ||
); | ||
|
||
export function Execute(query, format){ | ||
if (!format) format = "CSV"; | ||
if (!query) return ""; | ||
return chdb.Execute(Buffer.from(query+"\0"), Buffer.from(format+"\0")); | ||
function db(format, path) { | ||
this.format = format || 'JSONCompact'; | ||
this.path = path || '.'; | ||
this.query = function(query, format){ | ||
if (!query) return ""; | ||
if (!format) format = "CSV"; | ||
return chdb.Execute(Buffer.from(query+"\0"), Buffer.from(format+"\0")); | ||
}.bind(this); | ||
this.session = function(query, format, path) { | ||
if (!query) return ""; | ||
if (!format) format = "CSV"; | ||
if (!path) path = "/tmp"; | ||
return chdb.ExecuteSession(Buffer.from(query+"\0"), Buffer.from(format+"\0"), Buffer.from(path+"\0")); | ||
}.bind(this); | ||
return this; | ||
} | ||
|
||
export { chdb, db }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
{ | ||
"name": "chdb-bun", | ||
"version": "1.0.4", | ||
"module": "index.js", | ||
"type": "module", | ||
"author": "Lorenzo Mangani <[email protected]>", | ||
"license": "Apache2.0", | ||
"scripts": { | ||
"build": "cd lib && gcc -shared -fPIC -o libchdb_bun.so libchdb_bun.c -lchdb" | ||
}, | ||
"devDependencies": { | ||
"bun-types": "^0.5.0" | ||
}, | ||
"directories":{ | ||
"lib": "lib" | ||
} | ||
} |