9#include <unordered_map>
32 return std::format(
"orm_m{}_{}", rowIndex, logicalName);
38struct InsertColumnBinding
40 std::string logicalName;
52[[nodiscard]]
inline auto insertColumnBindings(model::ModelView model) -> std::vector<InsertColumnBinding>
54 std::vector<InsertColumnBinding> bindings;
56 for (
const auto& column : model->columns)
60 const auto target = model.resolveTarget(column);
61 if (target ==
nullptr)
63 throw std::invalid_argument{
"To-one column has no target model in the schema"};
66 for (
const auto& relatedColumn : target->columns)
68 if (relatedColumn.isPrimaryKey)
70 bindings.push_back({std::format(
"{}_{}", column.name, relatedColumn.name), &relatedColumn});
74 else if (not column.isAutoIncrement)
76 bindings.push_back({std::string{column.name}, &column});
97 "batch inserts are not supported by this command generator"};
145 std::unordered_map<BackendType, std::unique_ptr<BackendProvider>> backends;
171 const std::vector<binding::PrimaryKey>& ownerKeys,
bool joinedValues,
A backend-neutral database runtime error.
CommandGeneratorFactory(CommandGeneratorFactory &&)=default
auto getCommandGenerator(BackendType backendType) const -> const CommandGenerator &
auto getBackend(BackendType backendType) const -> const BackendProvider &
CommandGeneratorFactory(const CommandGeneratorFactory &)=delete
auto registerBackend(std::unique_ptr< BackendProvider > backend) -> void
auto operator=(const CommandGeneratorFactory &) -> CommandGeneratorFactory &=delete
auto operator=(CommandGeneratorFactory &&) -> CommandGeneratorFactory &=default
CommandGeneratorFactory()
virtual auto insert(model::ModelView model) const -> std::string=0
virtual auto select(model::ModelView model, const SelectSpec &spec) const -> SelectStatement=0
virtual auto update(model::ModelView model, const UpdateSpec &spec) const -> Statement=0
virtual auto insertMany(model::ModelView, const InsertManySpec &) const -> std::string
virtual ~CommandGenerator()=default
virtual auto dropTable(model::ModelView model) const -> std::string=0
virtual auto createTable(model::ModelView model) const -> std::string=0
virtual auto remove(model::ModelView model, const Predicate &predicate) const -> Statement=0
auto remove(model::ModelView model, const Predicate &predicate) const -> Statement override
auto dropTable(model::ModelView model) const -> std::string override
auto insert(model::ModelView model) const -> std::string override
auto createTable(model::ModelView model) const -> std::string override
auto insertMany(model::ModelView model, const InsertManySpec &spec) const -> std::string override
auto select(model::ModelView model, const SelectSpec &spec) const -> SelectStatement override
DefaultCommandGenerator(const SqlDialect &dialect, BackendType backend=BackendType::Empty)
auto update(model::ModelView model, const UpdateSpec &spec) const -> Statement override
std::vector< query::QueryValue > PrimaryKey
auto linkInsertSpec(model::ModelView owner, model::RelationView relation, const binding::PrimaryKey &ownerKey, const binding::PrimaryKey &targetKey) -> InsertIfAbsentSpec
auto collectionSelectStatement(const SqlDialect &dialect, model::ModelView owner, model::RelationView relation, std::string targetSelectSql, const std::vector< binding::PrimaryKey > &ownerKeys, bool joinedValues, BackendType backend=BackendType::Empty) -> Statement
auto unlinkStatement(const SqlDialect &dialect, model::ModelView owner, model::RelationView relation, const binding::PrimaryKey &ownerKey, const binding::PrimaryKey &targetKey, BackendType backend=BackendType::Empty) -> Statement
auto linkStatement(const SqlDialect &dialect, model::ModelView owner, model::RelationView relation, const binding::PrimaryKey &ownerKey, const binding::PrimaryKey &targetKey, BackendType backend=BackendType::Empty) -> Statement
auto dropTableStatements(const SqlDialect &dialect, model::ModelView owner) -> std::vector< std::string >
auto createTableStatements(const SqlDialect &dialect, model::ModelView owner, BackendType backend=BackendType::Empty) -> std::vector< std::string >
query::detail::UpdateSpec UpdateSpec
query::detail::Predicate Predicate
auto insertManyParameterName(std::size_t rowIndex, std::string_view logicalName) -> std::string
query::detail::SelectSpec SelectSpec
Statement SelectStatement
auto operator==(const InsertManySpec &) const -> bool=default
Trivially-copyable handle to one model in immutable Schema storage.