Skip to content

Commit

Permalink
Merge pull request #190 from michaelsbradleyjr/lib_c_immutable_query
Browse files Browse the repository at this point in the history
update doc comments for cozo_run_query
  • Loading branch information
zh217 authored Oct 30, 2023
2 parents ae9771c + 02afa95 commit f79c9b1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
21 changes: 10 additions & 11 deletions cozo-lib-c/cozo_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern "C" {
*
* `engine`: which storage engine to use, can be "mem", "sqlite" or "rocksdb".
* `path`: should contain the UTF-8 encoded path name as a null-terminated C-string.
* `db_id`: will contain the id of the database opened.
* `db_id`: will contain the ID of the database opened.
* `options`: options for the DB constructor: engine dependent.
*
* When the function is successful, null pointer is returned,
Expand All @@ -37,24 +37,23 @@ char *cozo_open_db(const char *engine, const char *path, const char *options, in
/**
* Close a database.
*
* `id`: the ID representing the database to close.
* `db_id`: the ID representing the database to close.
*
* Returns `true` if the database is closed,
* `false` if it has already been closed, or does not exist.
*/
bool cozo_close_db(int32_t id);
bool cozo_close_db(int32_t db_id);

/**
* Run query against a database.
*
* `db_id`: the ID representing the database to run the query.
* `script_raw`: a UTF-8 encoded C-string for the CozoScript to execute.
* `params_raw`: a UTF-8 encoded C-string for the params of the query,
* in JSON format. You must always pass in a valid JSON map,
* even if you do not use params in your query
* (pass "{}" in this case).
* `errored`: will point to `false` if the query is successful,
* `true` if an error occurred.
* `db_id`: the ID representing the database to run the query.
* `script_raw`: a UTF-8 encoded C-string for the CozoScript to execute.
* `params_raw`: a UTF-8 encoded C-string for the params of the query,
* in JSON format. You must always pass in a valid JSON map,
* even if you do not use params in your query
* (pass "{}" in this case).
* `immutable_query`: whether the query is read-only.
*
* Returns a UTF-8-encoded C-string that **must** be freed with `cozo_free_str`.
* The string contains the JSON return value of the query.
Expand Down
23 changes: 11 additions & 12 deletions cozo-lib-c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ lazy_static! {
///
/// `engine`: which storage engine to use, can be "mem", "sqlite" or "rocksdb".
/// `path`: should contain the UTF-8 encoded path name as a null-terminated C-string.
/// `db_id`: will contain the id of the database opened.
/// `db_id`: will contain the ID of the database opened.
/// `options`: options for the DB constructor: engine dependent.
///
/// When the function is successful, null pointer is returned,
Expand Down Expand Up @@ -76,29 +76,28 @@ pub unsafe extern "C" fn cozo_open_db(

/// Close a database.
///
/// `id`: the ID representing the database to close.
/// `db_id`: the ID representing the database to close.
///
/// Returns `true` if the database is closed,
/// `false` if it has already been closed, or does not exist.
#[no_mangle]
pub unsafe extern "C" fn cozo_close_db(id: i32) -> bool {
pub unsafe extern "C" fn cozo_close_db(db_id: i32) -> bool {
let db = {
let mut dbs = HANDLES.dbs.lock().unwrap();
dbs.remove(&id)
dbs.remove(&db_id)
};
db.is_some()
}

/// Run query against a database.
///
/// `db_id`: the ID representing the database to run the query.
/// `script_raw`: a UTF-8 encoded C-string for the CozoScript to execute.
/// `params_raw`: a UTF-8 encoded C-string for the params of the query,
/// in JSON format. You must always pass in a valid JSON map,
/// even if you do not use params in your query
/// (pass "{}" in this case).
/// `errored`: will point to `false` if the query is successful,
/// `true` if an error occurred.
/// `db_id`: the ID representing the database to run the query.
/// `script_raw`: a UTF-8 encoded C-string for the CozoScript to execute.
/// `params_raw`: a UTF-8 encoded C-string for the params of the query,
/// in JSON format. You must always pass in a valid JSON map,
/// even if you do not use params in your query
/// (pass "{}" in this case).
/// `immutable_query`: whether the query is read-only.
///
/// Returns a UTF-8-encoded C-string that **must** be freed with `cozo_free_str`.
/// The string contains the JSON return value of the query.
Expand Down

0 comments on commit f79c9b1

Please sign in to comment.