update sqlitecpp & merge property settings into properties
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
ff9bf0c14a
commit
88ca7769d1
39 changed files with 412 additions and 253 deletions
|
|
@ -8,9 +8,12 @@
|
|||
|
||||
#include <objects/blueprint.hpp>
|
||||
#include <objects/entity.hpp>
|
||||
#include <objects/property.hpp>
|
||||
#include <persistence/function_context.hpp>
|
||||
#include <persistence/project.hpp>
|
||||
|
||||
IkarusBlueprint::IkarusBlueprint(IkarusProject * project, IkarusId id):
|
||||
IkarusObject{project, id} {}
|
||||
|
||||
IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char const * name) {
|
||||
LOG_INFO("creating new blueprint");
|
||||
|
||||
|
|
@ -19,7 +22,7 @@ IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char c
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
auto * ctx = project->function_context();
|
||||
auto * ctx = project->get_function_context();
|
||||
|
||||
if (name == nullptr) {
|
||||
ctx->set_error("name is nullptr", true, IkarusErrorInfo_Source_Client, IkarusErrorInfo_Type_Client_Input);
|
||||
|
|
@ -31,12 +34,12 @@ IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char c
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
LOG_DEBUG("project={}; name={}", project->path().c_str(), name);
|
||||
LOG_DEBUG("project={}; name={}", project->get_path().c_str(), name);
|
||||
|
||||
VTRYRV(
|
||||
auto id,
|
||||
auto const id,
|
||||
nullptr,
|
||||
project->db()
|
||||
project->get_db()
|
||||
->transact([name](auto * db) -> cppbase::Result<IkarusId, sqlitecpp::TransactionError> {
|
||||
LOG_VERBOSE("creating blueprint in objects table");
|
||||
|
||||
|
|
@ -79,14 +82,15 @@ void ikarus_blueprint_delete(IkarusBlueprint * blueprint) {
|
|||
return;
|
||||
}
|
||||
|
||||
auto * ctx = blueprint->project->function_context();
|
||||
auto * ctx = blueprint->get_project()->get_function_context();
|
||||
|
||||
LOG_DEBUG("blueprint={}", blueprint->id);
|
||||
LOG_DEBUG("blueprint={}", blueprint->get_id());
|
||||
|
||||
TRYRV(
|
||||
,
|
||||
blueprint->project->db()
|
||||
->execute("DELETE FROM `objects` WHERE `id` = ?", blueprint->id)
|
||||
blueprint->get_project()
|
||||
->get_db()
|
||||
->execute("DELETE FROM `objects` WHERE `id` = ?", blueprint->get_id())
|
||||
.on_error([ctx](auto const& err) {
|
||||
ctx->set_error(
|
||||
fmt::format("failed to delete blueprint from objects table: {}", err),
|
||||
|
|
@ -99,7 +103,7 @@ void ikarus_blueprint_delete(IkarusBlueprint * blueprint) {
|
|||
|
||||
LOG_VERBOSE("blueprint was successfully deleted from database, freeing blueprint");
|
||||
|
||||
blueprint->project->remove_blueprint(blueprint);
|
||||
blueprint->get_project()->uncache_blueprint(blueprint);
|
||||
|
||||
LOG_VERBOSE("successfully deleted blueprint");
|
||||
}
|
||||
|
|
@ -112,15 +116,16 @@ size_t ikarus_blueprint_get_property_count(IkarusBlueprint const * blueprint) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
auto * ctx = blueprint->project->function_context();
|
||||
auto * ctx = blueprint->get_project()->get_function_context();
|
||||
|
||||
LOG_DEBUG("blueprint={}", blueprint->id);
|
||||
LOG_DEBUG("blueprint={}", blueprint->get_id());
|
||||
|
||||
VTRYRV(
|
||||
auto count,
|
||||
0,
|
||||
blueprint->project->db()
|
||||
->query_one<int>("SELECT COUNT(*) FROM `blueprint_properties` WHERE `blueprint` = ?;", blueprint->id)
|
||||
blueprint->get_project()
|
||||
->get_db()
|
||||
->query_one<int>("SELECT COUNT(*) FROM `blueprint_properties` WHERE `blueprint` = ?;", blueprint->get_id())
|
||||
.on_error([ctx](auto const& err) {
|
||||
ctx->set_error(
|
||||
fmt::format("failed to fetch blueprint property count: {}", err),
|
||||
|
|
@ -148,25 +153,26 @@ void ikarus_blueprint_get_properties(
|
|||
return;
|
||||
}
|
||||
|
||||
auto * ctx = blueprint->project->function_context();
|
||||
auto * ctx = blueprint->get_project()->get_function_context();
|
||||
|
||||
if (properties_out == nullptr) {
|
||||
ctx->set_error("properties_out is null", true, IkarusErrorInfo_Source_Client, IkarusErrorInfo_Type_Client_Input);
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_DEBUG("blueprint={}; properties_out_size={}", blueprint->id, properties_out_size);
|
||||
LOG_DEBUG("blueprint={}; properties_out_size={}", blueprint->get_id(), properties_out_size);
|
||||
|
||||
IkarusId ids[properties_out_size];
|
||||
|
||||
TRYRV(
|
||||
,
|
||||
blueprint->project->db()
|
||||
blueprint->get_project()
|
||||
->get_db()
|
||||
->query_many_buffered<IkarusId>(
|
||||
"SELECT `id` FROM `properties` WHERE `source` = ?",
|
||||
static_cast<IkarusId *>(ids),
|
||||
properties_out_size,
|
||||
blueprint->id
|
||||
blueprint->get_id()
|
||||
)
|
||||
.on_error([ctx](auto const& err) {
|
||||
ctx->set_error(
|
||||
|
|
@ -182,7 +188,7 @@ void ikarus_blueprint_get_properties(
|
|||
|
||||
for (size_t i = 0; i < properties_out_size; ++i) {
|
||||
/// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||
properties_out[i] = blueprint->project->get_property(ids[i]);
|
||||
properties_out[i] = blueprint->get_project()->get_property(ids[i]);
|
||||
}
|
||||
|
||||
LOG_VERBOSE("successfully fetched blueprint properties");
|
||||
|
|
@ -196,15 +202,16 @@ size_t ikarus_blueprint_get_linked_entity_count(IkarusBlueprint const * blueprin
|
|||
return 0;
|
||||
}
|
||||
|
||||
auto * ctx = blueprint->project->function_context();
|
||||
auto * ctx = blueprint->get_project()->get_function_context();
|
||||
|
||||
LOG_DEBUG("blueprint={}", blueprint->id);
|
||||
LOG_DEBUG("blueprint={}", blueprint->get_id());
|
||||
|
||||
VTRYRV(
|
||||
auto count,
|
||||
0,
|
||||
blueprint->project->db()
|
||||
->query_one<int>("SELECT COUNT(*) FROM `entity_blueprint_links` WHERE `blueprint` = ?;", blueprint->id)
|
||||
blueprint->get_project()
|
||||
->get_db()
|
||||
->query_one<int>("SELECT COUNT(*) FROM `entity_blueprint_links` WHERE `blueprint` = ?;", blueprint->get_id())
|
||||
.on_error([ctx](auto const& err) {
|
||||
ctx->set_error(
|
||||
fmt::format("failed to fetch blueprint linked entity count: {}", err),
|
||||
|
|
@ -232,25 +239,26 @@ void ikarus_blueprint_get_linked_entities(
|
|||
return;
|
||||
}
|
||||
|
||||
auto * ctx = blueprint->project->function_context();
|
||||
auto * ctx = blueprint->get_project()->get_function_context();
|
||||
|
||||
if (entities_out == nullptr) {
|
||||
ctx->set_error("entities_out is null", true, IkarusErrorInfo_Source_Client, IkarusErrorInfo_Type_Client_Input);
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_DEBUG("blueprint={}; entities_out_size={}", blueprint->id, entities_out_size);
|
||||
LOG_DEBUG("blueprint={}; entities_out_size={}", blueprint->get_id(), entities_out_size);
|
||||
|
||||
IkarusId ids[entities_out_size];
|
||||
|
||||
TRYRV(
|
||||
,
|
||||
blueprint->project->db()
|
||||
blueprint->get_project()
|
||||
->get_db()
|
||||
->query_many_buffered<IkarusId>(
|
||||
"SELECT `entity` FROM `entity_blueprint_links` WHERE `blueprint` = ?",
|
||||
static_cast<IkarusId *>(ids),
|
||||
entities_out_size,
|
||||
blueprint->id
|
||||
blueprint->get_id()
|
||||
)
|
||||
.on_error([ctx](auto const& err) {
|
||||
ctx->set_error(
|
||||
|
|
@ -266,7 +274,7 @@ void ikarus_blueprint_get_linked_entities(
|
|||
|
||||
for (size_t i = 0; i < entities_out_size; ++i) {
|
||||
/// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||
entities_out[i] = blueprint->project->get_entity(ids[i]);
|
||||
entities_out[i] = blueprint->get_project()->get_entity(ids[i]);
|
||||
}
|
||||
|
||||
LOG_VERBOSE("successfully fetched blueprint linked entities");
|
||||
|
|
@ -286,7 +294,7 @@ IkarusObject const * ikarus_blueprint_to_object_const(IkarusBlueprint const * bl
|
|||
|
||||
// auto * ctx = blueprint->project->function_context();
|
||||
|
||||
LOG_DEBUG("blueprint={}", blueprint->id);
|
||||
LOG_DEBUG("blueprint={}", blueprint->get_id());
|
||||
|
||||
LOG_VERBOSE("successfully casted blueprint to object");
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue