libmp/include/database.h

49 lines
1.8 KiB
C
Raw Normal View History

2024-07-02 01:44:07 +00:00
#pragma once
#include "package.h"
#include <sqlite3.h>
#define HASH_LEN 32
2024-07-02 01:44:07 +00:00
typedef enum lm_query_index {
QUERY_CREATE_TABLE = 0,
QUERY_INSERT_PACKAGE = 1,
QUERY_SELECT_PACKAGE = 2,
QUERY_DELETE_PACKAGE = 3,
QUERY_ALL_PACKAGE = 4,
2024-07-02 01:44:07 +00:00
} lm_query_index_t;
extern char *queries[];
typedef struct lm_database {
sqlite3_stmt *st;
sqlite3 *sql;
char *dir;
lm_pkg_t *pkg;
2024-07-02 01:44:07 +00:00
} lm_database_t;
typedef bool (*lm_database_files_eachfunc_t)(lm_pkg_t *pkg, char *path, char *hash, void *data);
typedef bool (*lm_database_keeps_eachfunc_t)(lm_pkg_t *pkg, char *path, void *data);
lm_database_t *lm_database_new(char *path);
void lm_database_free(lm_database_t *db);
bool lm_database_find(lm_database_t *db, lm_pkg_t *pkg, char *name);
bool lm_database_next(lm_database_t *db, lm_pkg_t *pkg);
2024-07-02 01:44:07 +00:00
bool lm_database_add(lm_database_t *db, lm_pkg_t *pkg);
bool lm_database_del(lm_database_t *db, lm_pkg_t *pkg);
bool lm_database_files_foreach(lm_database_t *db, lm_pkg_t *pkg, lm_database_files_eachfunc_t func, void *data);
bool lm_database_files_matches(lm_database_t *db, lm_pkg_t *pkg, char *path, char *hash);
2024-07-02 01:44:07 +00:00
bool lm_database_files_add(lm_database_t *db, lm_pkg_t *pkg, char *path, char *hash);
bool lm_database_files_get(lm_database_t *db, lm_pkg_t *pkg, char *path, char *hash);
bool lm_database_files_del(lm_database_t *db, lm_pkg_t *pkg);
2024-07-02 01:44:07 +00:00
bool lm_database_keeps_foreach(lm_database_t *db, lm_pkg_t *pkg, lm_database_keeps_eachfunc_t func, void *data);
bool lm_database_keeps_load(lm_database_t *db, lm_pkg_t *pkg);
bool lm_database_keeps_save(lm_database_t *db, lm_pkg_t *pkg);
bool lm_database_keeps_del(lm_database_t *db, lm_pkg_t *pkg);
bool lm_database_changes_update(lm_database_t *db, lm_pkg_t *pkg, char *file);
char *lm_database_changes_get(lm_database_t *db, lm_pkg_t *pkg);
bool lm_database_changes_del(lm_database_t *db, lm_pkg_t *pkg);