Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for chdb connection related C API #293

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions programs/local/chdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct query_queue
{
std::mutex mutex;
std::condition_variable query_cv; // For query submission
std::condition_variable result_cv;
std::condition_variable result_cv; // For query result retrieval
query_request current_query;
local_result_v2 * current_result = nullptr;
bool has_query = false;
Expand All @@ -75,15 +75,47 @@ struct query_queue
};
#endif

/**
* Connection structure for chDB
* Contains server instance, connection state, and query processing queue
*/
struct chdb_conn
{
void * server; // LocalServer * server;
bool connected;
void * queue; // query_queue*
void * server; /* ClickHouse LocalServer instance */
bool connected; /* Connection state flag */
void * queue; /* Query processing queue */
};

/**
* Creates a new chDB connection.
* Only one active connection is allowed per process.
* Creating a new connection with different path requires closing existing connection.
*
* @param argc Number of command-line arguments
* @param argv Command-line arguments array (--path=<db_path> to specify database location)
* @return Pointer to connection pointer, or NULL on failure
* @note Default path is ":memory:" if not specified
*/
CHDB_EXPORT struct chdb_conn ** connect_chdb(int argc, char ** argv);

/**
* Closes an existing chDB connection and cleans up resources.
* Thread-safe function that handles connection shutdown and cleanup.
*
* @param conn Pointer to connection pointer to close
*/
CHDB_EXPORT void close_conn(struct chdb_conn ** conn);

/**
* Executes a query on the given connection.
* Thread-safe function that handles query execution in a separate thread.
*
* @param conn Connection to execute query on
* @param query SQL query string to execute
* @param format Output format string (e.g., "CSV", default format)
* @return Query result structure containing output or error message
* @note Returns error result if connection is invalid or closed
*/
CHDB_EXPORT struct local_result_v2 * query_conn(struct chdb_conn * conn, const char * query, const char * format);

#ifdef __cplusplus
Expand Down