21#ifndef __CWIST_ORM_H__
22#define __CWIST_ORM_H__
27#include <cjson/cJSON.h>
198 const char *where_clause);
225 const char *where_clause, cJSON **result);
232 const cJSON *data,
const char *returning_col,
236 const char *returning_col,
int *out);
239 const cJSON *data,
const char *returning_col,
243 const cJSON *data,
const char *returning_col,
260#define cwist_orm_insert_r(orm, table, data, returning_col, out) \
262 int *: cwist_orm_insert_returning_int, \
263 long *: cwist_orm_insert_returning_long, \
264 long long *: cwist_orm_insert_returning_llong, \
265 cJSON **: cwist_orm_insert_returning_json)((orm), (table), (data), (returning_col), (out))
375 size_t row,
size_t column);
382 const char *where_clause, cJSON **out);
385 const char *where_clause,
int *out);
388 const char *where_clause,
long *out);
391 const char *where_clause,
long long *out);
394 const char *where_clause,
double *out);
397 const char *where_clause,
char **out);
424 const char *where_clause, int64_t *out);
436 const cJSON *data,
const char *returning_col,
453#define cwist_orm_select_one(orm, table, column, where, out) \
455 int *: cwist_orm_select_one_int, \
456 long *: cwist_orm_select_one_long, \
457 long long *: cwist_orm_select_one_llong, \
458 double *: cwist_orm_select_one_double, \
459 char **: cwist_orm_select_one_string, \
460 cJSON **: cwist_orm_select_one_json)((orm), (table), (column), (where), (out))
cwist_error_t cwist_orm_select_one_int(cwist_orm_t *orm, const char *table, const char *column, const char *where_clause, int *out)
Select a single column value from the first matching row as an int.
cwist_error_t cwist_orm_query(cwist_orm_t *orm, const char *sql, cJSON **result)
Execute a SELECT query and return the result set.
const cwist_orm_value_t * cwist_orm_result_cell(const cwist_orm_result_t *result, size_t row, size_t column)
Read one cell of a typed result set.
cwist_error_t cwist_orm_select_one_json(cwist_orm_t *orm, const char *table, const char *column, const char *where_clause, cJSON **out)
Select a single column value from the first matching row as JSON.
cwist_error_t cwist_orm_insert_returning_i64(cwist_orm_t *orm, const char *table, const cJSON *data, const char *returning_col, int64_t *out)
Insert a row and return an integer column exactly as an int64_t.
enum cwist_orm_value_type cwist_orm_value_type_t
Storage class of a typed result cell.
cwist_error_t cwist_orm_select_one_double(cwist_orm_t *orm, const char *table, const char *column, const char *where_clause, double *out)
Select a single column value from the first matching row as a double.
struct cwist_orm_result cwist_orm_result_t
Column-typed result set produced by cwist_orm_query_typed().
struct cwist_orm_value cwist_orm_value_t
One cell of a column-typed result set.
cwist_error_t cwist_orm_select(cwist_orm_t *orm, const char *table, const char *columns, const char *where_clause, cJSON **result)
Convenience SELECT helper.
cwist_error_t cwist_orm_insert_returning_json(cwist_orm_t *orm, const char *table, const cJSON *data, const char *returning_col, cJSON **out)
Insert a row and return a JSON value from the new row.
cwist_error_t cwist_orm_delete(cwist_orm_t *orm, const char *table, const char *where_clause)
Delete rows from a table.
void cwist_orm_use_dialect(cwist_orm_t *orm, cwist_orm_dialect_t dialect)
Select the SQL dialect used for query generation.
cwist_error_t cwist_orm_insert_returning_int(cwist_orm_t *orm, const char *table, const cJSON *data, const char *returning_col, int *out)
Insert a row and return a column value as an int.
cwist_error_t cwist_orm_insert_returning_llong(cwist_orm_t *orm, const char *table, const cJSON *data, const char *returning_col, long long *out)
Insert a row and return a column value as a long long.
cwist_orm_value_type
Storage class of a typed result cell.
cwist_orm_dialect
Supported SQL dialects for query generation.
cwist_orm_t * cwist_orm_open_socket(int socket_fd)
Create an ORM session from an existing SQL socket.
enum cwist_orm_dialect cwist_orm_dialect_t
Supported SQL dialects for query generation.
cwist_error_t cwist_orm_select_one_llong(cwist_orm_t *orm, const char *table, const char *column, const char *where_clause, long long *out)
Select a single column value from the first matching row as a long long.
cwist_error_t cwist_orm_select_one_i64(cwist_orm_t *orm, const char *table, const char *column, const char *where_clause, int64_t *out)
Select a single integer cell exactly as an int64_t.
void cwist_orm_immediate_commit(bool enable)
Toggle automatic commit mode.
cwist_error_t cwist_orm_select_one_string(cwist_orm_t *orm, const char *table, const char *column, const char *where_clause, char **out)
Select a single column value from the first matching row as a string.
cwist_error_t cwist_orm_exec(cwist_orm_t *orm, const char *sql)
Execute a non-query SQL statement.
void cwist_orm_close_socket(cwist_orm_t *orm)
Destroy an ORM session and close its underlying socket.
cwist_error_t cwist_orm_insert(cwist_orm_t *orm, const char *table, const cJSON *data)
Insert a JSON object into a table.
void cwist_orm_result_free(cwist_orm_result_t *result)
Release a result set from cwist_orm_query_typed().
cwist_error_t cwist_orm_commit(cwist_orm_t *orm)
Commit the current transaction.
cwist_error_t cwist_orm_update(cwist_orm_t *orm, const char *table, const cJSON *data, const char *where_clause)
Update rows in a table.
struct cwist_orm cwist_orm_t
Opaque ORM session handle.
cwist_error_t cwist_orm_rollback(cwist_orm_t *orm)
Roll back the current transaction.
cwist_error_t cwist_orm_insert_returning_long(cwist_orm_t *orm, const char *table, const cJSON *data, const char *returning_col, long *out)
Insert a row and return a column value as a long.
cwist_error_t cwist_orm_query_typed(cwist_orm_t *orm, const char *sql, cwist_orm_result_t **result)
Execute a SELECT-style query and return column-typed rows.
size_t cwist_orm_result_column_index(const cwist_orm_result_t *result, const char *column)
Find a column index by name in a typed result set.
cwist_error_t cwist_orm_select_one_long(cwist_orm_t *orm, const char *table, const char *column, const char *where_clause, long *out)
Select a single column value from the first matching row as a long.
Integrated error structure used throughout the system.
Column-typed result set produced by cwist_orm_query_typed().
cwist_orm_value_t * cells
One cell of a column-typed result set.
cwist_orm_value_type_t type
Unified error code and type definitions for the CWIST system layer.