99 lines
5.2 KiB
C
99 lines
5.2 KiB
C
#ifndef DB_OPS_POSTGRES_H
|
|
#define DB_OPS_POSTGRES_H
|
|
|
|
#include "db_ops.h"
|
|
|
|
typedef struct postgres_db_stmt postgres_db_stmt_t;
|
|
|
|
int postgres_db_init(const char* connection_string);
|
|
void postgres_db_close(void);
|
|
int postgres_db_is_available(void);
|
|
const char* postgres_db_last_error(void);
|
|
const char* postgres_db_get_database_path(void);
|
|
|
|
int postgres_db_apply_schema(void);
|
|
|
|
int postgres_db_set_thread_connection(void* connection);
|
|
void postgres_db_clear_thread_connection(void);
|
|
|
|
int postgres_db_open_worker_connection(const char* db_path, void** out_connection);
|
|
void postgres_db_close_worker_connection(void* connection);
|
|
|
|
int postgres_db_prepare(const char* sql, postgres_db_stmt_t** out_stmt);
|
|
int postgres_db_bind_text_param(postgres_db_stmt_t* stmt, int index, const char* value);
|
|
int postgres_db_bind_int_param(postgres_db_stmt_t* stmt, int index, int value);
|
|
int postgres_db_bind_int64_param(postgres_db_stmt_t* stmt, int index, long long value);
|
|
int postgres_db_step_stmt(postgres_db_stmt_t* stmt);
|
|
int postgres_db_reset_stmt(postgres_db_stmt_t* stmt);
|
|
const char* postgres_db_column_text_value(postgres_db_stmt_t* stmt, int col);
|
|
int postgres_db_column_int_value(postgres_db_stmt_t* stmt, int col);
|
|
long long postgres_db_column_int64_value(postgres_db_stmt_t* stmt, int col);
|
|
double postgres_db_column_double_value(postgres_db_stmt_t* stmt, int col);
|
|
void postgres_db_finalize_stmt(postgres_db_stmt_t* stmt);
|
|
|
|
int postgres_db_log_subscription_created(const char* sub_id, const char* wsi_ptr,
|
|
const char* client_ip, const char* filter_json);
|
|
int postgres_db_log_subscription_closed(const char* sub_id, const char* client_ip);
|
|
int postgres_db_log_subscription_disconnected(const char* client_ip);
|
|
int postgres_db_update_subscription_events_sent(const char* sub_id, int events_sent);
|
|
int postgres_db_cleanup_orphaned_subscriptions(void);
|
|
|
|
int postgres_db_get_event_pubkey(const char* event_id, char* pubkey_out, size_t pubkey_out_size);
|
|
int postgres_db_delete_event_by_id(const char* event_id, const char* requester_pubkey);
|
|
int postgres_db_delete_events_by_address(const char* pubkey, int kind,
|
|
const char* d_tag, long before_timestamp);
|
|
|
|
int postgres_db_is_pubkey_blacklisted(const char* pubkey);
|
|
int postgres_db_is_hash_blacklisted(const char* resource_hash);
|
|
int postgres_db_is_pubkey_whitelisted(const char* pubkey);
|
|
int postgres_db_count_active_whitelist_rules(void);
|
|
|
|
int postgres_db_count_with_sql(const char* sql, const char** bind_params, int bind_param_count, int* out_count);
|
|
char* postgres_db_execute_readonly_query_json(const char* query, const char* request_id,
|
|
char* error_message, size_t error_size,
|
|
int max_rows, int timeout_ms);
|
|
|
|
int postgres_db_get_total_event_count_ll(long long* out_count);
|
|
int postgres_db_get_event_count_since(time_t cutoff, long long* out_count);
|
|
int postgres_db_get_storage_size_bytes(long long* out_size);
|
|
cJSON* postgres_db_get_event_kind_distribution_rows(long long* out_total_events);
|
|
cJSON* postgres_db_get_top_pubkeys_rows(int limit);
|
|
cJSON* postgres_db_get_subscription_details_rows(void);
|
|
|
|
cJSON* postgres_db_get_all_config_rows(void);
|
|
char* postgres_db_get_config_value_dup(const char* key);
|
|
int postgres_db_set_config_value_full(const char* key, const char* value, const char* data_type,
|
|
const char* description, const char* category, int requires_restart);
|
|
int postgres_db_update_config_value_only(const char* key, const char* value);
|
|
int postgres_db_upsert_config_value(const char* key, const char* value, const char* data_type);
|
|
int postgres_db_store_relay_private_key_hex(const char* relay_privkey_hex);
|
|
char* postgres_db_get_relay_private_key_hex_dup(void);
|
|
int postgres_db_store_config_event(const cJSON* event);
|
|
|
|
int postgres_db_insert_event_with_json(const char* id, const char* pubkey, long long created_at,
|
|
int kind, const char* event_type, const char* content,
|
|
const char* sig, const char* tags_json, const char* event_json,
|
|
int* out_step_rc, int* out_extended_errcode);
|
|
int postgres_db_get_event_time_bounds(long long* out_min_created_at, long long* out_max_created_at);
|
|
int postgres_db_event_id_exists(const char* event_id, int* out_exists);
|
|
cJSON* postgres_db_retrieve_event_by_id(const char* event_id);
|
|
char* postgres_db_get_latest_event_pubkey_for_kind_dup(int kind);
|
|
|
|
int postgres_db_get_config_row_count(int* out_count);
|
|
|
|
int postgres_db_store_event_tags_cjson(const char* event_id, const cJSON* tags);
|
|
int postgres_db_populate_event_tags_from_existing(void);
|
|
|
|
int postgres_db_add_auth_rule(const char* rule_type, const char* pattern_type, const char* pattern_value);
|
|
int postgres_db_remove_auth_rule(const char* rule_type, const char* pattern_type, const char* pattern_value);
|
|
int postgres_db_delete_wot_whitelist_rules(void);
|
|
int postgres_db_count_wot_whitelist_rules(void);
|
|
|
|
int postgres_db_table_exists(const char* table_name, int* out_exists);
|
|
char* postgres_db_get_schema_version_dup(void);
|
|
int postgres_db_exec_sql(const char* sql);
|
|
int postgres_db_wal_checkpoint_passive(void);
|
|
int postgres_db_wal_checkpoint_truncate(void);
|
|
|
|
#endif // DB_OPS_POSTGRES_H
|