terra-sync / cnc

Seamless Database Replication tool
GNU General Public License v3.0
4 stars 2 forks source link

Database Operations API #5

Closed charmitro closed 6 months ago

charmitro commented 7 months ago

For the database operations, we need to provide an API where folks are going to use it to easily enable new/not-supported database support.

This means that we need to define a generic structure similar to the Linux Kernel Module one. Consider we have the following structs as a prototype:

struct d_str_t {
    const char *origin;
    const char *target;
};

struct db_t {
    struct d_str_t *host;
    struct d_str_t *user;
    struct d_str_t *password;
    struct d_str_t *port;
    struct d_str_t *database;

    void *host_conn;
    void *target_conn;  
};

struct options {
    enum backup_type;
    ... more ...
};

struct db_operations {
    int (*connect)(struct db_t *);
    void (*close)(struct db_t *);
    int (*replicate)(struct db_t *, struct options *);
};

With d_str_t being just a struct for holding two strings for convenience. A struct db_t holding all the information needed for connecting to the origin and target databases. Struct options will be used by replicate_db for any options regarding the replication/backup process.

A user will create all those structs and define the three functions connect, close, and replicate where the variable of type db_operations will hold.