Skip to content

Commit

Permalink
Explain the chDB ABI
Browse files Browse the repository at this point in the history
  • Loading branch information
auxten committed Jan 12, 2024
1 parent f780dc4 commit 9dd669f
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,65 @@ Here is a table outlining the current status of language bindings for chDB:
| PHP | n/a | Contributors Needed |
| Ruby | n/a | Contributors Needed |


### chDB stable ABI

chDB provides several stable ABIs for other language bindings.



The following is the definition of the `local_result` and `local_result_v2` structure:

```c
struct local_result
{
char * buf;
size_t len;
void * _vec; // std::vector<char> *, for freeing
double elapsed;
uint64_t rows_read;
uint64_t bytes_read;
};

struct local_result_v2
{
char * buf;
size_t len;
void * _vec; // std::vector<char> *, for freeing
double elapsed;
uint64_t rows_read;
uint64_t bytes_read;
char * error_message;
};
```

The following is the definition of the `query_stable`, `free_result` and `query_stable_v2`, `free_result_v2` functions.

```c
// v1 API
struct local_result * query_stable(int argc, char ** argv);
void free_result(struct local_result * result);

// v2 API added `char * error_message`.
struct local_result_v2 * query_stable_v2(int argc, char ** argv);
void free_result_v2(struct local_result_v2 * result);
```
#### Query
`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.
The difference is that `query_stable_v2` adds the `char * error_message` field.
You can check if the `error_message` field is `NULL` to determine if an error occurred.
#### Free Result
`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.
#### Known Issues
- By chDB v1.2.0, the `query_stable_v2``
returns nil if the query(eg. CREATE TABLE) successes but returns no data. We will change this behavior in the future.
### Need Help?
If you have already developed bindings for a language not listed above,
Expand Down

0 comments on commit 9dd669f

Please sign in to comment.