CringeDB/cringeDB.h
2022-08-29 15:43:05 +02:00

74 lines
3.0 KiB
C

//v1
//Copyright Cringe Studios
#ifndef _H_CRINGE_DB
#define _H_CRINGE_DB
typedef int cdb_error;
//connections
//----------------
typedef struct cdb_connection_impl * cdb_connection;
//cdb_connection cdb_databaseConnect(unsigned char ip1, unsigned char ip2, unsigned char ip3, unsigned char ip4, unsigned short port);
cdb_connection cdb_databaseConnect(unsigned char ip[4], unsigned short port, char * username, char * password);
cdb_connection cdb_databaseConnect6(unsigned char ip[16], unsigned short port, char * username, char * password);
cdb_connection cdb_databaseOpen(char * filePath);
void cdb_databaseClose(cdb_connection connection);
//----------------
//transactions
//----------------
typedef struct cdb_transaction_impl * cdb_transaction;
cdb_transaction cdb_transactionCreate(cdb_connection connection);
cdb_error cdb_transactionFlush(cdb_transaction transaction);
void cdb_transactionClear(cdb_transaction transaction);
cdb_error cdb_transactionClose(cdb_transaction cdb_transaction); // also flushes the transaction queue
//----------------
//DDL
//----------------
typedef struct cdb_table_impl * cdb_table;
cdb_error cdb_tableCreate(cdb_transaction transaction, char * tableName); //tableName can only consist of [a-z|A-Z|0-9|_]
cdb_table cdb_tableOpen(cdb_transaction transaction, char * tableName);
cdb_error cdb_tableClose(cdb_transaction transaction, cdb_table table);
cdb_error cdb_tableDelete(cdb_transaction transaction, cdb_table table);
cdb_error cdb_tableRename(cdb_transaction transaction, cdb_table table, char * newTableName);
//----------------
//DML
//----------------
typedef struct cdb_data_impl * cdb_data;
cdb_error cdb_tableClear(cdb_transaction transaction, cdb_table table);
cdb_error cdb_tableSize(cdb_transaction transaction, cdb_table table);
cdb_error cdb_tableEntryAdd(cdb_transaction transaction, cdb_table table, cdb_data data);
//cdb_tableEntryRemoveBy();
//----------------
//DCL only for network based connection
//----------------
#define CDB_TABLE_READ (1u)
#define CDB_TABLE_WRITE (1u << 1)
#define CDB_TABLE_MODIFY (1u << 2)
// TODO: more perms
typedef unsigned long cdb_permissions;
typedef struct cdb_user_impl * cdb_user;
//Table specific permissions
cdb_error cdb_userSetTablePermissions(cdb_connection connection, cdb_table table, cdb_user user, cdb_permissions permissions);
cdb_permissions cdb_userGetTablePermissions(cdb_connection connection, cdb_table table, cdb_user user);
//general permissions
cdb_error cdb_userSetGeneralPermissions(cdb_connection connection, cdb_user user, cdb_permissions permissions);
cdb_permissions cdb_userGetGeneralPermissions(cdb_connection connection, cdb_user user);
cdb_user cdb_userCreate(cdb_connection connection, char * username, char * password);
cdb_user cdb_userGet(cdb_connection connection, char * username);
cdb_error cdb_userDelete(cdb_connection connection, cdb_user deleter);
//----------------
#endif // _H_CRINGE_DB