Sqlite3 selector shorthand WIP
FossilOrigin-Name: 097b5c6a185f0a1eea5dff7a3e62c67147ad69dd8a8ecbeda59fc09eec67eda1
This commit is contained in:
parent
bbf0b19e2c
commit
d386a3cd23
5 changed files with 34 additions and 20 deletions
|
@ -48,7 +48,8 @@ namespace DB
|
|||
virtual void delete_app_by_client_id(const decltype(App::client_id)& id) {}
|
||||
virtual void delete_app_by_client_secret(const decltype(App::client_id)& id) {}
|
||||
/// There is only one config!
|
||||
virtual Config get_config() const {}
|
||||
virtual Config_t get_config() const
|
||||
{return {};}
|
||||
|
||||
/// These are just enums for Configuration and stuff, but Polymorphism
|
||||
/// handles the typing stuff already
|
||||
|
|
|
@ -19,7 +19,7 @@ using namespace std::string_literals;
|
|||
/** Informational struct for @function propagate */
|
||||
struct ppgate_sqlite_sel_info
|
||||
{
|
||||
std::variant<int, char*> type;
|
||||
std::variant<int*, std::string*> type;
|
||||
bool maybe_null;
|
||||
};
|
||||
|
||||
|
@ -30,7 +30,23 @@ propagate_sqlite_selection(sqlite3_stmt* stmt,
|
|||
std::initializer_list<struct ppgate_sqlite_sel_info>
|
||||
info)
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
for (size_t i = 0; i < info.size(); ++i)
|
||||
{
|
||||
if (info.begin()[i].maybe_null &&
|
||||
sqlite3_column_type(stmt, i) == SQLITE_NULL)
|
||||
continue;
|
||||
|
||||
if (holds_alternative<int*>(info.begin()[i].type))
|
||||
{
|
||||
*get<int*>(info.begin()[i].type) = sqlite3_column_int64(stmt, i);
|
||||
}
|
||||
else if (holds_alternative<string*>(info.begin()[i].type)) {
|
||||
*get<string*>(info.begin()[i].type) =
|
||||
reinterpret_cast<const char*>(sqlite3_column_text(stmt, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SQLite::SQLite(std::filesystem::path path)
|
||||
|
@ -314,7 +330,8 @@ void SQLite::delete_app_by_client_secret(const decltype(App::client_id)& id)
|
|||
{
|
||||
}
|
||||
|
||||
User SQLite::get_user(const decltype(User::acct)& acct)
|
||||
User
|
||||
SQLite::get_user(const decltype(User::acct)& acct)
|
||||
{
|
||||
User luser{};
|
||||
luser.id = 0;
|
||||
|
@ -329,10 +346,10 @@ User SQLite::get_user(const decltype(User::acct)& acct)
|
|||
{acct},
|
||||
[&luser](sqlite3_stmt* stmt) {
|
||||
propagate_sqlite_selection(stmt, {
|
||||
{&luser.id, },
|
||||
{&luser.display_name, },
|
||||
{&luser.bio, },
|
||||
{&luser.key, },
|
||||
{&luser.id, false},
|
||||
{&luser.display_name, true},
|
||||
{&luser.bio, true},
|
||||
{&luser.key, true},
|
||||
});
|
||||
luser.id = sqlite3_column_int64(stmt, 0);
|
||||
if (sqlite3_column_type(stmt, 1) != SQLITE_NULL)
|
||||
|
@ -354,11 +371,11 @@ User SQLite::get_user(const decltype(User::acct)& acct)
|
|||
}
|
||||
|
||||
// Retrieves the server configuration that's stored in the database
|
||||
virtual Config get_config() const override final
|
||||
Config_t get_config()
|
||||
{
|
||||
User luser{};
|
||||
luser.id = 0;
|
||||
luser.acct = acct;
|
||||
luser.acct = acct; //?
|
||||
luser.local = false;
|
||||
|
||||
sqlite_compile_to_cache(SQLiteCacheIndex::GET_CONFIG,
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace DB
|
|||
virtual void delete_app(decltype(App::id) id) override final;
|
||||
virtual void delete_app_by_client_id(const decltype(App::client_id)& id) override final;
|
||||
virtual void delete_app_by_client_secret(const decltype(App::client_id)& id) override final;
|
||||
virtual Config get_config() const override final;
|
||||
virtual Config_t get_config() const override final;
|
||||
|
||||
private:
|
||||
/**
|
||||
|
|
|
@ -6,15 +6,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include "languages.h"
|
||||
#include "random.h"
|
||||
|
||||
struct Config
|
||||
struct Config_t
|
||||
{
|
||||
Config() = default;
|
||||
~Config() = default;
|
||||
|
||||
struct
|
||||
{
|
||||
std::string const domain;
|
||||
|
@ -25,7 +22,7 @@ struct Config
|
|||
std::string const background_image;
|
||||
std::string const thumbnail;
|
||||
std::string const approval_required;
|
||||
std::array<Language, LANG_SIZE> const
|
||||
std::array<Language, LANG_SIZE> const languages;
|
||||
} instance;
|
||||
|
||||
struct
|
||||
|
|
|
@ -6,11 +6,10 @@
|
|||
#ifndef LANGUAGES_H
|
||||
#define LANGUAGES_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
enum class Language : std::uint16_t
|
||||
enum Language
|
||||
{
|
||||
EN_US,
|
||||
}
|
||||
LANG_SIZE,
|
||||
};
|
||||
|
||||
#endif // LANGUAGES_H
|
||||
|
|
Loading…
Reference in a new issue