|
cwist
Modern C web framework with libttak runtime
|
High-Performance Read-Optimal Persistent Store using SQLite. More...
#include <sqlite3.h>#include <stdbool.h>

Go to the source code of this file.
Classes | |
| struct | cwist_nuke_db_t |
| Nuke DB Context. More... | |
Macros | |
| #define | CWIST_NUKE_OK 0 |
| Return codes for cwist_nuke_init. | |
| #define | CWIST_NUKE_ERR_GENERIC (-1) |
| #define | CWIST_NUKE_ERR_LOW_MEMORY (-2) |
Typedefs | |
| typedef struct cwist_nuke_db_t | cwist_nuke_db_t |
| Nuke DB Context. | |
Functions | |
| int | cwist_nuke_init (const char *disk_path, int sync_interval_ms) |
| Initialize Nuke DB. | |
| int | cwist_nuke_sync (void) |
| Force synchronization from Memory to Disk. | |
| void | cwist_nuke_close (void) |
| Close databases safely. Performs a final synchronization before closing handles. | |
| sqlite3 * | cwist_nuke_get_db (void) |
| Get the raw SQLite3 handle for the In-Memory DB. | |
| void | cwist_nuke_signal_handler (int signum) |
| Internal signal handler. Typically set up by cwist_nuke_init. | |
| unsigned char * | cwist_nuke_serialize (sqlite3_int64 *out_size) |
| Serialize the in-memory database to a raw byte buffer. | |
| int | cwist_nuke_deserialize (unsigned char *data, sqlite3_int64 data_len) |
| Load a raw SQLite byte buffer into the in-memory database. | |
High-Performance Read-Optimal Persistent Store using SQLite.
Concept:
Definition in file nuke_db.h.
Nuke DB Context.
Logic:
Close databases safely. Performs a final synchronization before closing handles.
Close databases safely. Performs a final synchronization before closing handles.
Definition at line 293 of file nuke_db.c.
References cwist_nuke_sync().
Referenced by cwist_app_destroy(), cwist_app_use_nuke_db(), and cwist_nuke_init().
| int cwist_nuke_deserialize | ( | unsigned char * | data, |
| sqlite3_int64 | data_len | ||
| ) |
Load a raw SQLite byte buffer into the in-memory database.
Uses sqlite3_deserialize() to replace the current in-memory database content with the provided bytes. Ownership of data is transferred to SQLite (allocated with sqlite3_malloc()); do not free it yourself after a successful call.
| data | Buffer previously obtained via cwist_nuke_serialize() or cwist_db_sync_pull(). Must be sqlite3_malloc()-allocated. |
| data_len | Length of data in bytes. |
Load a raw SQLite byte buffer into the in-memory database.
| data | Serialized database buffer; ownership transfers to SQLite, which frees it on close (SQLITE_DESERIALIZE_FREEONCLOSE). |
| data_len | Length of data in bytes. |
Definition at line 520 of file nuke_db.c.
References cwist_nuke_db_t::is_disk_mode, and cwist_nuke_db_t::mem_db.
Get the raw SQLite3 handle for the In-Memory DB.
Get the raw SQLite3 handle for the In-Memory DB.
Definition at line 478 of file nuke_db.c.
References cwist_nuke_db_t::disk_db, cwist_nuke_db_t::is_disk_mode, and cwist_nuke_db_t::mem_db.
Referenced by cwist_app_get_db(), and cwist_app_use_nuke_db().
Initialize Nuke DB.
Loads the disk database into memory (if it exists). Sets up signal handlers for safe exit (SIGINT, SIGTERM). Starts a background thread for auto-sync if interval > 0.
| disk_path | Path to the persistent database file. |
| sync_interval_ms | Auto-sync interval in ms (0 to disable). |
Initialize Nuke DB.
| disk_path | Path to the on-disk SQLite database. |
| sync_interval_ms | Background sync interval in milliseconds. |
Definition at line 377 of file nuke_db.c.
References cwist_nuke_db_t::auto_sync, cwist_get_available_ram(), cwist_nuke_close(), CWIST_NUKE_ERR_GENERIC, CWIST_NUKE_ERR_LOW_MEMORY, CWIST_NUKE_OK, cwist_strdup(), cwist_nuke_db_t::disk_db, cwist_nuke_db_t::disk_path, cwist_nuke_db_t::is_disk_mode, cwist_nuke_db_t::load_successful, cwist_nuke_db_t::mem_db, and cwist_nuke_db_t::sync_interval_ms.
Referenced by cwist_app_use_nuke_db().
| unsigned char * cwist_nuke_serialize | ( | sqlite3_int64 * | out_size | ) |
Serialize the in-memory database to a raw byte buffer.
Uses sqlite3_serialize() for direct byte-level access to the SQLite image, which avoids the overhead of the backup API and enables encryption or network transfer without a temporary file.
The returned buffer is allocated by sqlite3_malloc() and must be freed with sqlite3_free(). Returns NULL on failure or when NukeDB is not initialised.
| [out] | out_size | Set to the number of bytes in the returned buffer. |
Serialize the in-memory database to a raw byte buffer.
| out_size | Receives the serialized byte count. |
Definition at line 497 of file nuke_db.c.
References cwist_nuke_db_t::disk_db, cwist_nuke_db_t::is_disk_mode, and cwist_nuke_db_t::mem_db.
Internal signal handler. Typically set up by cwist_nuke_init.
Internal signal handler. Typically set up by cwist_nuke_init.
| signum | Signal number; unused. |
Definition at line 487 of file nuke_db.c.
References CWIST_UNUSED.
Force synchronization from Memory to Disk.
Force synchronization from Memory to Disk.
Definition at line 228 of file nuke_db.c.
References cwist_nuke_db_t::disk_db, cwist_nuke_db_t::is_disk_mode, cwist_nuke_db_t::load_successful, and cwist_nuke_db_t::mem_db.
Referenced by cwist_nuke_close().