@@ -66,7 +66,7 @@ struct query_queue
6666{
6767 std::mutex mutex;
6868 std::condition_variable query_cv; // For query submission
69- std::condition_variable result_cv;
69+ std::condition_variable result_cv; // For query result retrieval
7070 query_request current_query;
7171 local_result_v2 * current_result = nullptr ;
7272 bool has_query = false ;
@@ -75,15 +75,47 @@ struct query_queue
7575};
7676#endif
7777
78+ /* *
79+ * Connection structure for chDB
80+ * Contains server instance, connection state, and query processing queue
81+ */
7882struct chdb_conn
7983{
80- void * server; // LocalServer * server;
81- bool connected;
82- void * queue; // query_queue*
84+ void * server; /* ClickHouse LocalServer instance */
85+ bool connected; /* Connection state flag */
86+ void * queue; /* Query processing queue */
8387};
8488
89+ /* *
90+ * Creates a new chDB connection.
91+ * Only one active connection is allowed per process.
92+ * Creating a new connection with different path requires closing existing connection.
93+ *
94+ * @param argc Number of command-line arguments
95+ * @param argv Command-line arguments array (--path=<db_path> to specify database location)
96+ * @return Pointer to connection pointer, or NULL on failure
97+ * @note Default path is ":memory:" if not specified
98+ */
8599CHDB_EXPORT struct chdb_conn ** connect_chdb (int argc, char ** argv);
100+
101+ /* *
102+ * Closes an existing chDB connection and cleans up resources.
103+ * Thread-safe function that handles connection shutdown and cleanup.
104+ *
105+ * @param conn Pointer to connection pointer to close
106+ */
86107CHDB_EXPORT void close_conn (struct chdb_conn ** conn);
108+
109+ /* *
110+ * Executes a query on the given connection.
111+ * Thread-safe function that handles query execution in a separate thread.
112+ *
113+ * @param conn Connection to execute query on
114+ * @param query SQL query string to execute
115+ * @param format Output format string (e.g., "CSV", default format)
116+ * @return Query result structure containing output or error message
117+ * @note Returns error result if connection is invalid or closed
118+ */
87119CHDB_EXPORT struct local_result_v2 * query_conn (struct chdb_conn * conn, const char * query, const char * format);
88120
89121#ifdef __cplusplus
0 commit comments