|
1 | 1 |
|
2 | 2 | import { dlopen, FFIType, suffix, CString, ptr } from "bun:ffi"; |
| 3 | + |
3 | 4 | const path = `lib/libchdb_bun.${suffix}`; |
| 5 | + |
4 | 6 | const { symbols: chdb, } = dlopen(path, { |
5 | 7 | Execute: { |
6 | 8 | args: [FFIType.cstring, FFIType.cstring], |
7 | 9 | returns:FFIType.cstring, |
8 | 10 | }, |
| 11 | + ExecuteSession: { |
| 12 | + args: [FFIType.cstring, FFIType.cstring, FFIType.cstring], |
| 13 | + returns:FFIType.cstring, |
| 14 | + }, |
9 | 15 | }, |
10 | 16 | ); |
11 | 17 |
|
12 | | -export function Execute(query, format){ |
13 | | - if (!format) format = "CSV"; |
14 | | - if (!query) return ""; |
15 | | - return chdb.Execute(Buffer.from(query+"\0"), Buffer.from(format+"\0")); |
| 18 | +function db(format, path) { |
| 19 | + this.format = format || 'JSONCompact'; |
| 20 | + this.path = path || '.'; |
| 21 | + this.query = function(query, format){ |
| 22 | + if (!query) return ""; |
| 23 | + if (!format) format = "CSV"; |
| 24 | + return chdb.Execute(Buffer.from(query+"\0"), Buffer.from(format+"\0")); |
| 25 | + }.bind(this); |
| 26 | + this.session = function(query, format, path) { |
| 27 | + if (!query) return ""; |
| 28 | + if (!format) format = "CSV"; |
| 29 | + if (!path) path = "/tmp"; |
| 30 | + return chdb.ExecuteSession(Buffer.from(query+"\0"), Buffer.from(format+"\0"), Buffer.from(path+"\0")); |
| 31 | + }.bind(this); |
| 32 | + return this; |
16 | 33 | } |
| 34 | + |
| 35 | +export { chdb, db }; |
0 commit comments