Atlas Game Manager
A game manager for f95 and dlsite written in c++
Loading...
Searching...
No Matches
Column.hpp
Go to the documentation of this file.
1//
2// Created by kj16609 on 5/24/23.
3//
4
5#pragma once
6#ifndef ATLASGAMEMANAGER_COLUMN_HPP
7#define ATLASGAMEMANAGER_COLUMN_HPP
8
9#include <string>
10
11#include "Transaction.hpp"
12#include "core/fgl/string_literal.hpp"
13
15{
16 template < auto Data >
17 consteval const auto& make_static()
18 {
19 return Data;
20 }
21
22 template < fgl::string_literal column, fgl::string_literal table_name, fgl::string_literal table_key_name >
23 static consteval std::string_view update_query()
24 {
25 constexpr fgl::string_literal begin { "UPDATE " };
26 constexpr fgl::string_literal set { " SET " };
27 constexpr fgl::string_literal where { " = ? WHERE " };
28 constexpr fgl::string_literal end { " = ?" };
29 constexpr auto& static_data {
31 };
32 return std::string_view( static_data.begin(), static_data.size() - 1 );
33 }
34
35 template < fgl::string_literal column, fgl::string_literal table_name, fgl::string_literal table_key_name >
36 static consteval std::string_view select_query()
37 {
38 constexpr fgl::string_literal begin { "SELECT " };
39 constexpr fgl::string_literal from { " FROM " };
40 constexpr fgl::string_literal where { " WHERE " };
41 constexpr fgl::string_literal end { " = ?" };
42
43 constexpr auto& static_data {
45 };
46
47 return std::string_view( static_data.begin(), static_data.size() - 1 );
48 }
49
50 template < fgl::string_literal str, fgl::string_literal last >
51 consteval auto combineStringLiteralCSV()
52 {
53 constexpr fgl::string_literal comma { ", " };
54 return str + comma + last;
55 }
56
57 template < fgl::string_literal str, fgl::string_literal... rest >
58 requires( sizeof...( rest ) > 1 )
59 consteval auto combineStringLiteralCSV()
60 {
61 constexpr fgl::string_literal comma { ", " };
62 return str + comma + combineStringLiteralCSV< rest... >();
63 }
64
65 template < fgl::string_literal table, fgl::string_literal table_key_name, fgl::string_literal... columns >
66 static consteval std::string_view select_query_t()
67 {
68 constexpr fgl::string_literal begin { "SELECT " };
69 constexpr fgl::string_literal from { " FROM " };
70 constexpr fgl::string_literal where { " WHERE " };
71 constexpr fgl::string_literal end { " = ?" };
72
73 constexpr auto& static_data { make_static<
74 begin + combineStringLiteralCSV< columns... >() + from + table + where + table_key_name + end >() };
75
76 return std::string_view( static_data.begin(), static_data.size() - 1 );
77 }
78} // namespace atlas::database::utility
79
80#endif //ATLASGAMEMANAGER_COLUMN_HPP
Definition Column.hpp:15
static consteval std::string_view select_query()
Definition Column.hpp:36
static consteval std::string_view update_query()
Definition Column.hpp:23
consteval auto combineStringLiteralCSV()
Definition Column.hpp:51
static consteval std::string_view select_query_t()
Definition Column.hpp:66
consteval const auto & make_static()
Definition Column.hpp:17