Skip to content

Commit 9dd669f

Browse files
committed
Explain the chDB ABI
1 parent f780dc4 commit 9dd669f

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

bindings.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,65 @@ Here is a table outlining the current status of language bindings for chDB:
1717
| PHP | n/a | Contributors Needed |
1818
| Ruby | n/a | Contributors Needed |
1919

20+
21+
### chDB stable ABI
22+
23+
chDB provides several stable ABIs for other language bindings.
24+
25+
26+
27+
The following is the definition of the `local_result` and `local_result_v2` structure:
28+
29+
```c
30+
struct local_result
31+
{
32+
char * buf;
33+
size_t len;
34+
void * _vec; // std::vector<char> *, for freeing
35+
double elapsed;
36+
uint64_t rows_read;
37+
uint64_t bytes_read;
38+
};
39+
40+
struct local_result_v2
41+
{
42+
char * buf;
43+
size_t len;
44+
void * _vec; // std::vector<char> *, for freeing
45+
double elapsed;
46+
uint64_t rows_read;
47+
uint64_t bytes_read;
48+
char * error_message;
49+
};
50+
```
51+
52+
The following is the definition of the `query_stable`, `free_result` and `query_stable_v2`, `free_result_v2` functions.
53+
54+
```c
55+
// v1 API
56+
struct local_result * query_stable(int argc, char ** argv);
57+
void free_result(struct local_result * result);
58+
59+
// v2 API added `char * error_message`.
60+
struct local_result_v2 * query_stable_v2(int argc, char ** argv);
61+
void free_result_v2(struct local_result_v2 * result);
62+
```
63+
64+
#### Query
65+
`query_stable` and `query_stable_v2` accept the same parameters just like the `clickhouse-local` command line tool. You can check `queryToBuffer` function in [LocalChdb.cpp](programs/local/LocalChdb.cpp) as an example.
66+
67+
The difference is that `query_stable_v2` adds the `char * error_message` field.
68+
You can check if the `error_message` field is `NULL` to determine if an error occurred.
69+
70+
#### Free Result
71+
`free_result` and `free_result_v2` are used to free the `local_result` and `local_result_v2` memory. For GC languages, you can call `free_result` or `free_result_v2` in the destructor of the object.
72+
73+
#### Known Issues
74+
75+
- By chDB v1.2.0, the `query_stable_v2``
76+
returns nil if the query(eg. CREATE TABLE) successes but returns no data. We will change this behavior in the future.
77+
78+
2079
### Need Help?
2180
If you have already developed bindings for a language not listed above,
2281

0 commit comments

Comments
 (0)