update_data

Function update_data 

Source
#[unsafe(no_mangle)]
pub extern "C" fn update_data( state: *mut AppDbState, json_ptr: *const c_char, ) -> *const c_char
Expand description

Updates an existing record in the database.

The record is identified by the ID field in the provided JSON data. If no record with that ID exists, the operation returns an error.

§Parameters

  • state - Pointer to the database state instance
  • json_ptr - Null-terminated C string containing updated JSON data

§Returns

Returns a JSON-formatted C string containing the updated record on success, or an error response if the record doesn’t exist or on failure.

§Safety

Both parameters must be valid pointers.

§Examples

use std::ffi::CString;
use offline_first_core::{create_db, update_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":"new_hash","data":{"updated":true}}"#).unwrap();
let result = update_data(db_state, json.as_ptr());