You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
proxysql/include/PgSQL_Static_Harvester.h

71 lines
1.9 KiB

#ifndef CLASS_PGSQL_STATIC_HARVESTER_H
#define CLASS_PGSQL_STATIC_HARVESTER_H
#ifdef PROXYSQLGENAI
#include "Discovery_Schema.h"
#include <string>
#include <vector>
#include <memory>
#include <pthread.h>
typedef struct pg_conn PGconn;
class PgSQL_Static_Harvester {
private:
std::string pgsql_host;
int pgsql_port;
std::string pgsql_user;
std::string pgsql_password;
std::string pgsql_dbname;
PGconn* pgsql_conn;
pthread_mutex_t conn_lock;
Discovery_Schema* catalog;
int current_run_id;
std::string source_dsn;
std::string server_version;
int connect_pgsql();
void disconnect_pgsql();
int execute_query(const std::string& query, std::vector<std::vector<std::string>>& results);
std::string get_pgsql_version();
static bool is_valid_schema_name(const std::string& name);
static std::string escape_sql_string(const std::string& str);
public:
PgSQL_Static_Harvester(
const std::string& host,
int port,
const std::string& user,
const std::string& password,
const std::string& dbname,
const std::string& catalog_path
);
~PgSQL_Static_Harvester();
int init();
void close();
int start_run(const std::string& target_id, const std::string& notes = "");
int finish_run(const std::string& notes = "");
int get_run_id() const { return current_run_id; }
int harvest_schemas(const std::string& only_schema = "");
int harvest_objects(const std::string& only_schema = "");
int harvest_columns(const std::string& only_schema = "");
int harvest_indexes(const std::string& only_schema = "");
int harvest_foreign_keys(const std::string& only_schema = "");
int harvest_view_definitions(const std::string& only_schema = "");
int build_quick_profiles();
int rebuild_fts_index();
int run_full_harvest(const std::string& target_id, const std::string& only_schema = "", const std::string& notes = "");
std::string get_harvest_stats();
std::string get_harvest_stats(int run_id);
};
#endif /* PROXYSQLGENAI */
#endif /* CLASS_PGSQL_STATIC_HARVESTER_H */