close_database

Function close_database 

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

Explicitly closes the database connection.

This function provides explicit connection management, which is particularly useful for Flutter hot restart scenarios where resources need to be cleaned up before reconnecting.

§Parameters

  • db_state - Pointer to the database state instance

§Returns

Returns a JSON-formatted C string indicating success or failure.

§Safety

The db_state parameter must be a valid pointer.

§Examples

use std::ffi::CString;
use offline_first_core::{create_db, close_database};

let db_name = CString::new("test_db").unwrap();
let db_state = create_db(db_name.as_ptr());

// Before hot restart or application shutdown
let result = close_database(db_state);

§Notes

In LMDB, connections are automatically closed when the environment is dropped. This function serves as an explicit indicator that the connection should no longer be used.