mirror of
https://github.com/getml/sqlgen.git
synced 2026-01-10 03:20:00 -06:00
Began writing to_create_table(...)
This commit is contained in:
24
include/sqlgen/parsing/is_primary_key.hpp
Normal file
24
include/sqlgen/parsing/is_primary_key.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef SQLGEN_PARSING_IS_PRIMARY_KEY_HPP_
|
||||
#define SQLGEN_PARSING_IS_PRIMARY_KEY_HPP_
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include "../PrimaryKey.hpp"
|
||||
|
||||
namespace sqlgen::parsing {
|
||||
|
||||
template <class T>
|
||||
class is_primary_key;
|
||||
|
||||
template <class T>
|
||||
class is_primary_key : public std::false_type {};
|
||||
|
||||
template <class T>
|
||||
class is_primary_key<PrimaryKey<T>> : public std::true_type {};
|
||||
|
||||
template <class T>
|
||||
constexpr bool is_primary_key_v = is_primary_key<std::remove_cvref_t<T>>::value;
|
||||
|
||||
} // namespace sqlgen::parsing
|
||||
|
||||
#endif
|
||||
59
include/sqlgen/parsing/to_create_table.hpp
Normal file
59
include/sqlgen/parsing/to_create_table.hpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef SQLGEN_PARSING_TO_CREATE_TABLE_HPP_
|
||||
#define SQLGEN_PARSING_TO_CREATE_TABLE_HPP_
|
||||
|
||||
#include <rfl.hpp>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "../dynamic/Column.hpp"
|
||||
#include "../dynamic/CreateTable.hpp"
|
||||
#include "../dynamic/Table.hpp"
|
||||
#include "../dynamic/Type.hpp"
|
||||
|
||||
namespace sqlgen::parsing {
|
||||
|
||||
namespace internal {
|
||||
|
||||
template <class FieldType>
|
||||
std::string to_name() {
|
||||
using Name = typename FieldType::Name;
|
||||
return Name().str();
|
||||
}
|
||||
|
||||
template <class FieldType>
|
||||
dynamic::Type to_type() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
template <class FieldType>
|
||||
dynamic::Column to_column() {
|
||||
return dynamic::Column{.name = to_name<FieldType>(),
|
||||
.type = to_type<FieldType>()};
|
||||
}
|
||||
|
||||
template <class Fields, int... _is>
|
||||
std::vector<dynamic::Column> make_columns(std::integer_sequence<int, _is...>) {
|
||||
return std::vector<dynamic::Column>(
|
||||
{to_column<rfl::tuple_element_t<_is, Fields>>()...});
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
template <class T>
|
||||
requires std::is_class_v<std::remove_cvref_t<T>> &&
|
||||
std::is_aggregate_v<std::remove_cvref_t<T>>
|
||||
dynamic::CreateTable to_create_table() {
|
||||
using NamedTupleType = rfl::name_tuple_t<std::remove_cvref_t<T>>;
|
||||
using Fields = typename NamedTupleType::Fields;
|
||||
return dynamic::CreateTable{
|
||||
.table = dynamic::Table{.name = /*TODO*/},
|
||||
.columns = internal::make_columns<Fields>(
|
||||
std::make_integer_sequence<int, rfl::tuple_size_v<Fields>>),
|
||||
.if_not_exists = true};
|
||||
}
|
||||
|
||||
} // namespace sqlgen::parsing
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user