#[unsafe(no_mangle)]pub extern "C" fn push_data(
state: *mut AppDbState,
json_ptr: *const c_char,
) -> *const c_charExpand description
Inserts a new record into the database.
This function deserializes the provided JSON string into a LocalDbModel
and stores it in the database using the model’s ID as the key.
§Parameters
state- Pointer to the database state instancejson_ptr- Null-terminated C string containing JSON data
§Returns
Returns a JSON-formatted C string containing the operation result. The returned string must be freed by the caller.
§Safety
This function is unsafe because it dereferences raw pointers. Both parameters must be valid pointers to their respective types.
§Examples
use std::ffi::CString;
use offline_first_core::{create_db, push_data};
let db_name = CString::new("test_db").unwrap();
let db_state = create_db(db_name.as_ptr());
let json = CString::new(r#"{"id":"1","hash":"abc123","data":{"name":"test"}}"#).unwrap();
let result = push_data(db_state, json.as_ptr());§JSON Format
Expected JSON structure:
{
"id": "unique_identifier",
"hash": "content_hash",
"data": { /* arbitrary JSON data */ }
}