added shadowrun database

This commit is contained in:
2025-06-01 21:19:54 +02:00
parent 71f771b428
commit 69f7f625f8
20 changed files with 738 additions and 103 deletions

35
src/database/database.cpp Normal file
View File

@@ -0,0 +1,35 @@
#include "crow.h"
#include "database.hpp"
Database::Database() :
m_db(nullptr)
{}
Database::~Database() {
sqlite3_close(m_db);
}
bool Database::exec(const char* sqlQuery) {
char* errmsg = nullptr;
int rc = sqlite3_exec(m_db, sqlQuery, nullptr, nullptr, &errmsg);
if (rc != SQLITE_OK) {
CROW_LOG_ERROR << "SQL error: " << errmsg;
sqlite3_free(errmsg);
return false;
}
return true;
}
bool Database::exec(const std::string& sqlQuery)
{
exec(sqlQuery.c_str());
}
bool Database::open(){
int rc = sqlite3_open("example.db", &m_db);
if (rc) {
CROW_LOG_ERROR << "Can't open database: " << sqlite3_errmsg(m_db);
return false;
}
return true;
}

21
src/database/database.hpp Normal file
View File

@@ -0,0 +1,21 @@
#ifndef __DATABASE_H__
#define __DATABASE_H__
#include "sqlite3.h"
#include <string>
class Database {
public:
Database();
~Database();
bool open();
bool exec(const char* sqlQuery);
bool exec(const std::string& sqlQuery);
private:
sqlite3* m_db;
};
#endif // __DATABASE_H__