|
cwist
Modern C web framework with libttak runtime
|
Header: <cwist/core/db/sql.h>
Wrapper for SQLite3 database operations.
Opens a connection to a SQLite database file.
Opens a database from an in-memory SQLite image (e.g. a blob fetched by a WASM or edge host) via sqlite3_deserialize. The image is copied, so the caller keeps ownership of buf. readonly != 0 rejects writes with SQLITE_READONLY.
Serializes the database into a freshly allocated image buffer (free with cwist_free()), suitable for persisting back to a blob or for handing to cwist_db_open_memory().
Executes a non-query SQL command (INSERT, UPDATE, DELETE). Returns err_i16 = -1 when called with a NULL handle or SQL pointer so callers can safely guard inputs.
Executes a SELECT query. result is populated with a cJSON Array of Objects on success and reset to NULL if validation or SQLite execution fails.
Integrate the handle with the framework via cwist_app_use_db(app, "app.db"); — every incoming cwist_http_request then exposes the pointer at req->db.
Header: <cwist/core/db/migrate.h>
| Constant | Value | Meaning |
|---|---|---|
CWIST_MIGRATE_OK | 0 | Success |
CWIST_MIGRATE_ERR_GENERIC | -1 | General failure |
CWIST_MIGRATE_ERR_SQL | -2 | SQLite error |
CWIST_MIGRATE_ERR_ARGS | -3 | NULL or invalid arguments |
Applies all migrations whose version is greater than the current schema version, in ascending version order. Each migration runs inside its own transaction; on failure the transaction is rolled back and the error code is returned. The migrations array need not be sorted.
Rolls back the most recent steps applied migrations (pass 0 to roll back all). Skips migrations whose down_sql is NULL. Each rollback runs inside a transaction.
Returns the highest version number applied so far, 0 if no migrations have been applied, or -1 on error. Useful at startup to guard conditional migration logic.