summaryrefslogtreecommitdiff
path: root/src/cmd_util.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd_util.h')
-rw-r--r--src/cmd_util.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/cmd_util.h b/src/cmd_util.h
index ccab9f4..6187efe 100644
--- a/src/cmd_util.h
+++ b/src/cmd_util.h
@@ -25,6 +25,23 @@ yyjson_mut_val *failf(struct req *r, const char *code, const char *fmt, ...)
yyjson_mut_val *db_error(struct req *r);
yyjson_mut_val *db_sqlite_error(struct req *r);
void bind_text_or_null(sqlite3_stmt *st, int idx, const char *s);
+/* spec: "id:i,name:s,active:b" — i int, s text ("" for NULL), b bool,
+ * n nullable text (JSON null for NULL), r nullable int; columns from 0. */
+yyjson_mut_val *db_row_json(yyjson_mut_doc *doc, sqlite3_stmt *st,
+ const char *spec);
+/* types: one letter per bind — i int64_t, s const char *, n nullable
+ * const char *. Returns the statement bound at ?1.., NULL on prepare error. */
+sqlite3_stmt *db_prepare_bound(sqlite3 *db, const char *sql, const char *types,
+ ...);
+/* 0 on SQLITE_DONE, -1 when prepare fails, else the step result. */
+int db_exec_bound(sqlite3 *db, const char *sql, const char *types, ...);
+/* db_exec_bound with the request's error set: db_error on prepare failure,
+ * db_sqlite_error on any other step result. Returns 0 on success. */
+int req_exec(struct req *r, const char *sql, const char *types, ...);
+/* {"items":[db_row_json(spec) per row]} for a bound SELECT; NULL with
+ * db_error set when prepare fails. */
+yyjson_mut_val *req_list(struct req *r, const char *sql, const char *spec,
+ const char *types, ...);
int mkdir_p(const char *path, mode_t mode);
yyjson_mut_val *json_to_mut(yyjson_mut_doc *doc, const char *json);
int is_digits(const char *s);