#ifndef HAKO_H
#define HAKO_H
#pragma once
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#define INSERT 1
#define DELETE 2
typedef struct HK_Array HK_Array;
typedef struct HK_Batch HK_Batch;
typedef struct HK_CloudSync HK_CloudSync;
typedef struct HK_Config HK_Config;
typedef struct HK_Doc HK_Doc;
typedef struct HK_Engine HK_Engine;
typedef struct HK_NetSyncer HK_NetSyncer;
typedef struct HK_Query HK_Query;
typedef struct HK_RawDoc HK_RawDoc;
typedef struct HK_RawResultSet HK_RawResultSet;
typedef struct HK_ResultSet HK_ResultSet;
typedef struct HK_Transaction HK_Transaction;
typedef struct HK_ViewDoc HK_ViewDoc;
typedef struct HK_Watch HK_Watch;
typedef void (*HK_OnSnapshotCallback)(const char *collection,
const char *path,
int32_t kind,
void *user_data);
typedef bool (*HkWalkCallback)(const char *id,
uintptr_t id_len,
const uint8_t *bytes,
uintptr_t bytes_len,
void *userdata);
typedef bool (*HkViewWalkCallback)(const char *id,
uintptr_t id_len,
const struct HK_ViewDoc *view,
void *userdata);
#ifdef __cplusplus
extern "C" {
#endif
struct HK_Engine *hk_engine_open(const char *path);
bool hk_engine_is_indexes_ready(struct HK_Engine *engine);
bool hk_engine_await_quiescent(struct HK_Engine *engine, uint64_t timeout_ms);
char *hk_engine_quiescence_status(struct HK_Engine *engine);
struct HK_Config *hk_config_new(void);
void hk_config_free(struct HK_Config *config);
void hk_config_set_durability(struct HK_Config *config, int32_t mode);
void hk_config_set_encryption_key(struct HK_Config *config, const char *key);
int32_t hk_config_set_encrypted_collections(struct HK_Config *config, const char *collections_json);
void hk_config_set_audit_log(struct HK_Config *config, bool enabled, const char *path);
void hk_config_set_query_workers(struct HK_Config *config, uintptr_t count);
void hk_config_set_memory_limits(struct HK_Config *config,
uintptr_t mmap_size,
uintptr_t max_inlined_bytes);
void hk_config_set_storage_tuning(struct HK_Config *config,
uintptr_t page_size,
uintptr_t compaction_threshold,
uintptr_t group_commit_max_ops);
void hk_config_set_blob_threshold(struct HK_Config *config, uintptr_t threshold_bytes);
void hk_config_set_wal_reserve_bytes(struct HK_Config *config, uint64_t bytes);
char *hk_debug_write_stats(void);
struct HK_Engine *hk_engine_open_with_config(const char *path, struct HK_Config *config);
struct HK_Watch *hk_engine_watch(struct HK_Engine *engine,
const char *collection,
HK_OnSnapshotCallback callback,
void *user_data_ptr);
void hk_watch_free(struct HK_Watch *watch);
void hk_engine_free(struct HK_Engine *engine);
struct HK_Doc *hk_doc_new(void);
void hk_doc_free(struct HK_Doc *doc);
int32_t hk_doc_insert_str(struct HK_Doc *doc, const char *key, const char *value);
int32_t hk_doc_insert_int(struct HK_Doc *doc, const char *key, int64_t value);
int32_t hk_doc_insert_float(struct HK_Doc *doc, const char *key, double value);
int32_t hk_doc_insert_bool(struct HK_Doc *doc, const char *key, bool value);
int32_t hk_doc_insert_null(struct HK_Doc *doc, const char *key);
int32_t hk_doc_insert_bin(struct HK_Doc *doc, const char *key, const uint8_t *data, uintptr_t len);
int32_t hk_engine_insert(struct HK_Engine *engine,
const char *collection,
const char *doc_id,
const struct HK_Doc *doc);
int32_t hk_engine_insert_take(struct HK_Engine *engine,
const char *collection,
const char *doc_id,
struct HK_Doc *doc);
struct HK_Doc *hk_engine_get(struct HK_Engine *engine, const char *collection, const char *doc_id);
int32_t hk_engine_delete(struct HK_Engine *engine, const char *collection, const char *doc_id);
int32_t hk_engine_delete_local(struct HK_Engine *engine,
const char *collection,
const char *doc_id);
int32_t hk_engine_set_collection_local(struct HK_Engine *engine,
const char *collection,
int32_t local);
int32_t hk_engine_replicate_key(struct HK_Engine *engine,
const char *collection,
const char *doc_id);
int32_t hk_engine_replicate_collection(struct HK_Engine *engine, const char *collection);
int32_t hk_engine_vacuum_collection(struct HK_Engine *engine, const char *collection);
struct HK_Batch *hk_batch_new(void);
void hk_batch_free(struct HK_Batch *batch);
int32_t hk_batch_set(struct HK_Batch *batch,
const char *collection,
const char *doc_id,
struct HK_Doc *doc);
int32_t hk_batch_delete(struct HK_Batch *batch, const char *collection, const char *doc_id);
int32_t hk_batch_commit(struct HK_Engine *engine, struct HK_Batch *batch);
struct HK_Query *hk_query_new(const char *collection);
void hk_query_free(struct HK_Query *query);
int32_t hk_query_where_eq_str(struct HK_Query *query, const char *field, const char *value);
int32_t hk_query_where_eq_bool(struct HK_Query *query, const char *field, bool value);
int32_t hk_query_delete(struct HK_Engine *engine, struct HK_Query *query);
int32_t hk_query_delete_local(struct HK_Engine *engine, struct HK_Query *query);
int32_t hk_query_patch(struct HK_Engine *engine,
struct HK_Query *query,
const struct HK_Doc *patch_doc);
int32_t hk_query_where_eq_int(struct HK_Query *query, const char *field, int64_t value);
int32_t hk_query_where_ne_str(struct HK_Query *query, const char *field, const char *value);
int32_t hk_query_where_ne_int(struct HK_Query *query, const char *field, int64_t value);
int32_t hk_query_where_gt_str(struct HK_Query *query, const char *field, const char *value);
int32_t hk_query_where_gt_int(struct HK_Query *query, const char *field, int64_t value);
int32_t hk_query_where_gte_str(struct HK_Query *query, const char *field, const char *value);
int32_t hk_query_where_gte_int(struct HK_Query *query, const char *field, int64_t value);
int32_t hk_query_where_lt_str(struct HK_Query *query, const char *field, const char *value);
int32_t hk_query_where_lt_int(struct HK_Query *query, const char *field, int64_t value);
int32_t hk_query_where_lte_str(struct HK_Query *query, const char *field, const char *value);
int32_t hk_query_where_lte_int(struct HK_Query *query, const char *field, int64_t value);
int32_t hk_query_where_array_contains(struct HK_Query *query, const char *field, const char *value);
int32_t hk_query_where_array_contains_any(struct HK_Query *query,
const char *field,
struct HK_Array *array);
int32_t hk_query_where_not_in(struct HK_Query *query, const char *field, struct HK_Array *array);
int32_t hk_query_order_by(struct HK_Query *query, const char *field, bool ascending);
int32_t hk_query_limit(struct HK_Query *query, uintptr_t limit);
int32_t hk_query_defer_blobs(struct HK_Query *query, int defer);
int32_t hk_doc_resolve_blobs(struct HK_Engine *engine, const char *collection, struct HK_Doc *doc);
int32_t hk_query_offset(struct HK_Query *query, uintptr_t offset);
int32_t hk_query_select_field(struct HK_Query *query, const char *field);
char *hk_query_execute(struct HK_Engine *engine, const struct HK_Query *query);
struct HK_ResultSet *hk_query_execute_to_handles(struct HK_Engine *engine,
const struct HK_Query *query);
uintptr_t hk_result_set_count(struct HK_ResultSet *results);
struct HK_Doc *hk_result_set_get_doc(struct HK_ResultSet *results, uintptr_t index);
void hk_result_set_free(struct HK_ResultSet *results);
struct HK_RawResultSet *hk_query_execute_raw(struct HK_Engine *engine,
const struct HK_Query *query);
uintptr_t hk_rawresult_count(struct HK_RawResultSet *results);
struct HK_RawDoc *hk_rawresult_get(struct HK_RawResultSet *results, uintptr_t index);
void hk_rawresult_free(struct HK_RawResultSet *results);
const uint8_t *hk_rawdoc_bytes(const struct HK_RawDoc *doc, uintptr_t *len_out);
const char *hk_rawdoc_id(const struct HK_RawDoc *doc, uintptr_t *len_out);
int32_t hk_query_start_after_raw(struct HK_Query *query, const struct HK_RawDoc *anchor_doc);
struct HK_Doc *hk_rawdoc_to_doc(struct HK_Engine *engine,
const struct HK_RawDoc *raw_doc,
const char *collection);
int64_t hk_cursor_walk(struct HK_Engine *engine,
const struct HK_Query *query,
HkWalkCallback callback,
void *userdata);
struct HK_ViewDoc *hk_view_get(struct HK_Engine *engine,
const char *collection,
const char *doc_id);
void hk_view_free(struct HK_ViewDoc *view);
uintptr_t hk_view_field_count(const struct HK_ViewDoc *view);
bool hk_view_has_field(const struct HK_ViewDoc *view, const char *key);
bool hk_view_get_int(const struct HK_ViewDoc *view, const char *key, int64_t *out);
bool hk_view_get_float(const struct HK_ViewDoc *view, const char *key, double *out);
int32_t hk_view_get_bool(const struct HK_ViewDoc *view, const char *key);
const char *hk_view_get_str(const struct HK_ViewDoc *view, const char *key, uintptr_t *len_out);
const uint8_t *hk_view_get_bytes(const struct HK_ViewDoc *view,
const char *key,
uintptr_t *len_out);
struct HK_Doc *hk_view_to_doc(const struct HK_ViewDoc *view, const char *doc_id);
int64_t hk_cursor_walk_view(struct HK_Engine *engine,
const struct HK_Query *query,
HkViewWalkCallback callback,
void *userdata);
char *hk_result_set_to_json(struct HK_ResultSet *results);
char *hk_doc_to_json(const struct HK_Doc *doc);
const char *hk_last_error(void);
void hk_log_enable_stderr(void);
void hk_log_disable_stderr(void);
void hk_string_free(char *value);
int32_t hk_query_aggregate_count(struct HK_Query *query);
int32_t hk_query_aggregate_sum(struct HK_Query *query, const char *field);
int32_t hk_query_aggregate_avg(struct HK_Query *query, const char *field);
char *hk_query_execute_aggregation(struct HK_Engine *engine, const struct HK_Query *query);
int32_t hk_doc_insert_timestamp(struct HK_Doc *doc, const char *key, int64_t micros);
int32_t hk_doc_insert_server_timestamp(struct HK_Doc *doc, const char *key);
int32_t hk_engine_backup(struct HK_Engine *engine, const char *path);
int32_t hk_query_where_match(struct HK_Query *query, const char *field, const char *value);
int32_t hk_query_where_match_prefix(struct HK_Query *query, const char *field, const char *value);
int32_t hk_query_where_contains(struct HK_Query *query, const char *field, const char *value);
int32_t hk_query_where_starts_with(struct HK_Query *query, const char *field, const char *value);
char *hk_engine_list_collections(struct HK_Engine *engine);
struct HK_Array *hk_array_new(void);
void hk_array_free(struct HK_Array *array);
int32_t hk_array_append_str(struct HK_Array *array, const char *value);
int32_t hk_array_append_int(struct HK_Array *array, int64_t value);
int32_t hk_array_append_doc(struct HK_Array *array, const struct HK_Doc *doc);
int32_t hk_doc_insert_doc(struct HK_Doc *parent, const char *key, const struct HK_Doc *child);
int32_t hk_doc_insert_array(struct HK_Doc *doc, const char *key, struct HK_Array *array);
int32_t hk_engine_patch(struct HK_Engine *engine,
const char *collection,
const char *doc_id,
const struct HK_Doc *updates);
uint32_t hk_engine_create_index(struct HK_Engine *engine,
const char *collection,
const char *fields_json);
int32_t hk_engine_create_simple_index(struct HK_Engine *engine,
const char *collection,
const char *field);
int32_t hk_engine_create_fts_index(struct HK_Engine *engine,
const char *collection,
const char *field);
char *hk_engine_list_indexes(struct HK_Engine *engine, const char *collection);
struct HK_Transaction *hk_transaction_begin(struct HK_Engine *engine);
struct HK_Doc *hk_transaction_get(struct HK_Engine *engine,
struct HK_Transaction *tx,
const char *collection,
const char *doc_id);
int32_t hk_transaction_set(struct HK_Transaction *tx,
const char *collection,
const char *doc_id,
const struct HK_Doc *doc);
int32_t hk_transaction_commit(struct HK_Engine *engine, struct HK_Transaction *tx);
void hk_transaction_free(struct HK_Transaction *tx);
int32_t hk_engine_insert_subdoc(struct HK_Engine *engine,
const char *col,
const char *id,
const char *sub_col,
const char *sub_id,
const struct HK_Doc *doc);
int32_t hk_engine_compact(struct HK_Engine *engine);
char *hk_engine_get_stats(struct HK_Engine *engine);
int32_t hk_doc_insert_reference(struct HK_Doc *doc,
const char *key,
const char *target_collection,
const char *target_id);
struct HK_Doc *hk_engine_get_by_ref(struct HK_Engine *engine,
const struct HK_Doc *doc,
const char *field_key);
int32_t hk_query_start_after(struct HK_Query *query, const struct HK_Doc *anchor_doc);
int32_t hk_query_start_at(struct HK_Query *query, const struct HK_Doc *anchor_doc);
int32_t hk_query_end_at(struct HK_Query *query, const struct HK_Doc *anchor_doc);
int32_t hk_query_end_before(struct HK_Query *query, const struct HK_Doc *anchor_doc);
char *hk_engine_get_audit_log(struct HK_Engine *engine);
int32_t hk_query_where_or_str(struct HK_Query *query, const char *field, const char *value);
int32_t hk_query_where_or_int(struct HK_Query *query, const char *field, int64_t value);
int32_t hk_query_where_in(struct HK_Query *query, const char *field, struct HK_Array *array);
int32_t hk_engine_snapshot_indices(struct HK_Engine *engine);
void hk_config_set_compression(struct HK_Config *config, bool enabled, int32_t level);
void hk_config_set_background_maintenance(struct HK_Config *config, bool enabled);
struct HK_NetSyncer *hk_net_syncer_new(struct HK_Engine *engine,
const char *name,
const char *room_key);
int32_t hk_net_syncer_set_discovery(struct HK_NetSyncer *syncer, int32_t mode);
int32_t hk_net_syncer_start(struct HK_NetSyncer *syncer, uint16_t port);
char *hk_net_syncer_status(struct HK_NetSyncer *syncer);
void hk_net_syncer_free(struct HK_NetSyncer *syncer);
struct HK_CloudSync *hk_cloud_sync_new(struct HK_Engine *engine,
int32_t mode,
const char *client_id,
const char *room_name,
const char *room_key,
const char *auth_token);
struct HK_CloudSync *hk_cloud_sync_server_new(struct HK_Engine *engine,
const char *server_id,
const char *auth_token);
struct HK_CloudSync *hk_cloud_sync_client_new(struct HK_Engine *engine,
const char *client_id,
const char *room_name,
const char *room_key,
const char *auth_token);
int32_t hk_cloud_sync_start(struct HK_CloudSync *cloud_sync, const char *address);
char *hk_cloud_sync_status(struct HK_CloudSync *cloud_sync);
void hk_cloud_sync_stop(struct HK_CloudSync *cloud_sync);
void hk_cloud_sync_free(struct HK_CloudSync *cloud_sync);
#ifdef __cplusplus
} #endif
#endif