This library provides the low level C API for the SubZero. It's intended to be used by other languages to interface with the SubZero library.
The purpose of this library is to take an HTTP request and return a SQL statement that can be used to query a database and return the fully formed response body.
The HTTP request needs to conform to the SubZero HTTP request format (PostgREST compatible).
const char* db_type = "sqlite";
const char* db_schema_json = ""
"{"
" \"schemas\": ["
" {"
" \"name\": \"public\","
" \"objects\": ["
" {"
" \"kind\": \"table\","
" \"name\": \"clients\","
" \"columns\": ["
" {"
" \"name\": \"id\","
" \"data_type\": \"INTEGER\","
" \"primary_key\": true"
" },"
" {"
" \"name\": \"name\","
" \"data_type\": \"TEXT\","
" \"primary_key\": false"
" }"
" ],"
" \"foreign_keys\": []"
" }"
" ]"
" }"
" ]"
"}"
;
int main() {
if (db_schema == NULL) {
char* err = (char*)malloc(err_len);
printf("Error: %s\n", err);
free(err);
return -1;
}
const char* headers[] = {"Content-Type", "application/json", "Accept", "application/json"};
const char* env[] = {"user_id", "1"};
"GET",
"http://localhost/rest/projects?select=id,name",
NULL,
headers, 4,
env, 2
);
"public",
"/rest/",
"user",
db_schema,
req,
NULL
);
if (stmt == NULL) {
char* err = (char*)malloc(err_len);
printf("Error: %s\n", err);
free(err);
return -1;
}
printf("SQL: %s\n", sql);
printf("params: %s\n", params[0]);
printf("params_count: %d\n", params_count);
printf("params_types: %s\n", params_types[0]);
return 0;
}
struct sbz_DbSchema * sbz_db_schema_new(const char *db_type, const char *db_schema_json, const char *license_key)
void sbz_statement_free(struct sbz_Statement *statement)
struct sbz_Statement sbz_Statement
Definition subzero.h:135
int sbz_last_error_length(void)
const char * sbz_statement_sql(const struct sbz_Statement *statement)
struct sbz_DbSchema sbz_DbSchema
Definition subzero.h:124
const char *const * sbz_statement_params(const struct sbz_Statement *statement)
struct sbz_HTTPRequest sbz_HTTPRequest
Definition subzero.h:130
struct sbz_HTTPRequest * sbz_http_request_new(const char *method, const char *uri, const char *body, const char *const *headers, int headers_count, const char *const *env, int env_count)
void sbz_db_schema_free(struct sbz_DbSchema *schema)
const char *const * sbz_statement_params_types(const struct sbz_Statement *statement)
int sbz_statement_params_count(const struct sbz_Statement *statement)
int sbz_last_error_message(char *buffer, int length)
void sbz_http_request_free(struct sbz_HTTPRequest *request)