remove logging statements
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
f925d90d6b
commit
ee85c53354
6 changed files with 260 additions and 75 deletions
|
|
@ -27,7 +27,7 @@ IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char c
|
|||
}
|
||||
|
||||
void ikarus_blueprint_delete(IkarusBlueprint * blueprint) {
|
||||
ikarus::util::delete_object(blueprint->project, blueprint);
|
||||
ikarus::util::delete_object(blueprint);
|
||||
}
|
||||
|
||||
void ikarus_blueprint_get_properties(
|
||||
|
|
|
|||
|
|
@ -2,20 +2,36 @@
|
|||
|
||||
#include <cppbase/strings.hpp>
|
||||
|
||||
#include <objects/blueprint.hpp>
|
||||
#include <objects/util.hpp>
|
||||
#include <persistence/function_context.hpp>
|
||||
#include <persistence/project.hpp>
|
||||
|
||||
IkarusEntity * ikarus_entity_create(struct IkarusProject * project, char const * name) {
|
||||
LOG_INFO("creating new entity");
|
||||
|
||||
LOG_DEBUG("project={}; name={}", project->get_path().c_str(), name);
|
||||
|
||||
auto * ctx = project->get_function_context();
|
||||
|
||||
if (cppbase::is_empty_or_blank(name)) {
|
||||
ctx->set_error("name is empty or blank", true, IkarusErrorInfo_Source_Client, IkarusErrorInfo_Type_Client_Input);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// TODO
|
||||
return ikarus::util::insert_object(
|
||||
project,
|
||||
IkarusObjectType_Entity,
|
||||
name,
|
||||
[](auto * db, IkarusId id) { return db->execute("INSERT INTO `entities`(`id`) VALUES(?)", id); },
|
||||
[project](IkarusId id) { return project->get_entity(id); }
|
||||
).unwrap_value_or(nullptr);
|
||||
}
|
||||
|
||||
void ikarus_entity_delete(IkarusEntity * entity) {
|
||||
ikarus::util::delete_object(entity);
|
||||
}
|
||||
|
||||
bool ikarus_entity_is_linked_to_blueprint(IkarusEntity const * entity, struct IkarusBlueprint const * blueprint) {
|
||||
return ikarus::util::check_exists(
|
||||
entity,
|
||||
ikarus::util::ExistsQueryData<IkarusId>{
|
||||
.table_name = "entity_blueprint_links",
|
||||
.where_field_name = "blueprint",
|
||||
.where_field_value = blueprint->id,
|
||||
.relation_desc = "linked blueprints"
|
||||
}
|
||||
)
|
||||
.unwrap_value_or(false);
|
||||
}
|
||||
|
||||
bool ikarus_entity_link_to_blueprint(IkarusEntity * entity, struct IkarusBlueprint * blueprint) {}
|
||||
|
|
|
|||
|
|
@ -23,10 +23,6 @@ IkarusProperty::Data const & IkarusProperty::get_data() const {
|
|||
}
|
||||
|
||||
cppbase::Result<IkarusPropertyType, sqlitecpp::SingleQueryError> IkarusProperty::get_property_type(IkarusProject * project, IkarusId id) {
|
||||
LOG_DEBUG("fetching unboxed property type");
|
||||
|
||||
LOG_VERBOSE("project={};property={}", project->get_path().c_str(), id);
|
||||
|
||||
auto * ctx = project->get_function_context();
|
||||
|
||||
VTRY(
|
||||
|
|
@ -45,10 +41,6 @@ cppbase::Result<IkarusPropertyType, sqlitecpp::SingleQueryError> IkarusProperty:
|
|||
}
|
||||
|
||||
IKA_API void ikarus_property_delete(IkarusProperty * property) {
|
||||
LOG_INFO("deleting property");
|
||||
|
||||
LOG_VERBOSE("project={};property={}", property->project->get_path().c_str(), property->id);
|
||||
|
||||
auto * ctx = property->project->get_function_context();
|
||||
|
||||
TRYRV(, property->project->get_db()->execute("DELETE FROM `objects` WHERE `id` = ?", property->id).on_error([ctx](auto const & err) {
|
||||
|
|
@ -60,24 +52,14 @@ IKA_API void ikarus_property_delete(IkarusProperty * property) {
|
|||
);
|
||||
}));
|
||||
|
||||
LOG_VERBOSE("property was successfully deleted from database, freeing");
|
||||
|
||||
property->project->uncache(property);
|
||||
|
||||
LOG_VERBOSE("successfully deleted property");
|
||||
}
|
||||
|
||||
IkarusPropertyType ikarus_property_get_type(IkarusProperty const * property) {
|
||||
LOG_VERBOSE("fetching property type");
|
||||
|
||||
return IkarusProperty::get_property_type(property->project, property->id).unwrap_value_or(IkarusPropertyType_Toggle);
|
||||
}
|
||||
|
||||
IkarusPropertySource const * ikarus_property_get_source(IkarusProperty const * property) {
|
||||
LOG_VERBOSE("fetching property source");
|
||||
|
||||
LOG_VERBOSE("project={};property={}", property->project->get_path().c_str(), property->id);
|
||||
|
||||
auto * ctx = property->project->get_function_context();
|
||||
|
||||
VTRYRV(
|
||||
|
|
@ -112,10 +94,6 @@ IkarusPropertySource const * ikarus_property_get_source(IkarusProperty const * p
|
|||
}
|
||||
|
||||
IkarusValue * ikarus_property_get_default_value(IkarusProperty const * property) {
|
||||
LOG_VERBOSE("fetching property default value");
|
||||
|
||||
LOG_VERBOSE("project={};property={}", property->project->get_path().c_str(), property->id);
|
||||
|
||||
auto * ctx = property->project->get_function_context();
|
||||
|
||||
VTRYRV(
|
||||
|
|
|
|||
|
|
@ -28,10 +28,6 @@ template<typename InsertFunction, typename ObjectFactory>
|
|||
) {
|
||||
auto const * object_type_str = ikarus_object_type_to_string(type);
|
||||
|
||||
LOG_INFO("creating new {}", object_type_str);
|
||||
|
||||
LOG_DEBUG("project={}; name={}", project->get_path().c_str(), name);
|
||||
|
||||
auto * ctx = project->get_function_context();
|
||||
|
||||
if (cppbase::is_empty_or_blank(name)) {
|
||||
|
|
@ -43,14 +39,10 @@ template<typename InsertFunction, typename ObjectFactory>
|
|||
auto const id,
|
||||
project->get_db()
|
||||
->transact([&](auto * db) -> cppbase::Result<IkarusId, sqlitecpp::TransactionError> {
|
||||
LOG_VERBOSE("creating {} in objects table", object_type_str);
|
||||
|
||||
TRY(db->execute("INSERT INTO `objects` (`object_type`, `name`) VALUES(?, ?);", static_cast<int>(type), name));
|
||||
|
||||
auto id = ikarus_id_from_data_and_type(db->last_insert_rowid(), IkarusObjectType_Blueprint);
|
||||
|
||||
LOG_DEBUG("{} is {}", object_type_str, id);
|
||||
|
||||
TRY(insert_function(db, id));
|
||||
|
||||
return cppbase::ok(id);
|
||||
|
|
@ -65,23 +57,17 @@ template<typename InsertFunction, typename ObjectFactory>
|
|||
})
|
||||
);
|
||||
|
||||
LOG_VERBOSE("successfully created {}", object_type_str);
|
||||
|
||||
return cppbase::ok(object_factory(id));
|
||||
}
|
||||
|
||||
template<typename Object>
|
||||
requires std::derived_from<Object, IkarusObject>
|
||||
void delete_object(IkarusProject * project, Object * object) {
|
||||
void delete_object(Object * object) {
|
||||
auto object_type_str = ikarus_object_type_to_string(ikarus_id_get_object_type(object->id));
|
||||
|
||||
LOG_INFO("deleting {}", object_type_str);
|
||||
|
||||
LOG_DEBUG("project={}; {}={}", object_type_str, object->project->get_path().c_str(), object->id);
|
||||
|
||||
auto * ctx = object->project->get_function_context();
|
||||
|
||||
TRYRV(, project->get_db()->execute("DELETE FROM `objects` WHERE `id` = ?", object->id).on_error([&](auto const & err) {
|
||||
TRYRV(, object->project->get_db()->execute("DELETE FROM `objects` WHERE `id` = ?", object->id).on_error([&](auto const & err) {
|
||||
ctx->set_error(
|
||||
fmt::format("failed to delete {} from objects table: {}", object_type_str, err),
|
||||
true,
|
||||
|
|
@ -90,11 +76,7 @@ void delete_object(IkarusProject * project, Object * object) {
|
|||
);
|
||||
}));
|
||||
|
||||
LOG_VERBOSE("{} was successfully deleted from database, freeing", object_type_str);
|
||||
|
||||
project->uncache(object);
|
||||
|
||||
LOG_VERBOSE("successfully deleted {}", object_type_str);
|
||||
object->project->uncache(object);
|
||||
}
|
||||
|
||||
struct SingleQueryData {
|
||||
|
|
@ -107,10 +89,6 @@ template<typename T, typename Object>
|
|||
cppbase::Result<T, sqlitecpp::SingleQueryError> fetch_single_field(Object const * object, SingleQueryData const & query_data) {
|
||||
auto object_type_str = ikarus_object_type_to_string(ikarus_id_get_object_type(object->id));
|
||||
|
||||
LOG_VERBOSE("fetching property default value");
|
||||
|
||||
LOG_VERBOSE("project={};property={}", object->project->get_path().c_str(), object->id);
|
||||
|
||||
auto * ctx = object->project->get_function_context();
|
||||
|
||||
VTRY(
|
||||
|
|
@ -155,10 +133,6 @@ void fetch_multiple_buffered(
|
|||
|
||||
auto object_type_str = ikarus_object_type_to_string(ikarus_id_get_object_type(object->id));
|
||||
|
||||
LOG_VERBOSE("fetching {} {}", object_type_str, query_data.relation_desc);
|
||||
|
||||
LOG_VERBOSE("project={};{}={}", object->project->get_path().c_str(), object_type_str, object->id);
|
||||
|
||||
Selected select_buffer[buffer_size];
|
||||
|
||||
TRYRV(
|
||||
|
|
@ -185,8 +159,6 @@ void fetch_multiple_buffered(
|
|||
})
|
||||
);
|
||||
|
||||
LOG_DEBUG("{} {}: [{}]", object_type_str, query_data.relation_desc, fmt::join(select_buffer, select_buffer + buffer_size, ", "));
|
||||
|
||||
for (size_t i = 0; i < buffer_size; ++i) {
|
||||
VTRYRV(mapped_buffer[i], , transformer(object->project, ctx, select_buffer[i]));
|
||||
}
|
||||
|
|
@ -204,12 +176,8 @@ template<typename Object>
|
|||
cppbase::Result<cppbase::usize, sqlitecpp::QueryError> fetch_count(Object const * object, CountQueryData const & query_data) {
|
||||
auto * object_type_str = ikarus_object_type_to_string(ikarus_id_get_object_type(object->id));
|
||||
|
||||
LOG_VERBOSE("fetching {} {} count", object_type_str, query_data.relation_desc);
|
||||
|
||||
auto * ctx = object->project->get_function_context();
|
||||
|
||||
LOG_DEBUG("{}={}", object_type_str, object->id);
|
||||
|
||||
VTRY(
|
||||
auto count,
|
||||
object->project->get_db()
|
||||
|
|
@ -232,11 +200,42 @@ cppbase::Result<cppbase::usize, sqlitecpp::QueryError> fetch_count(Object const
|
|||
})
|
||||
);
|
||||
|
||||
LOG_DEBUG("{} {} count: {}", object_type_str, query_data.relation_desc, count);
|
||||
|
||||
LOG_VERBOSE("successfully fetched {} {} count", object_type_str, query_data.relation_desc);
|
||||
|
||||
return cppbase::ok(static_cast<size_t>(count));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
struct ExistsQueryData {
|
||||
std::string_view table_name;
|
||||
std::string_view where_field_name;
|
||||
T where_field_value;
|
||||
std::string_view relation_desc;
|
||||
};
|
||||
|
||||
template<typename Object, typename T>
|
||||
requires std::derived_from<Object, IkarusObject>
|
||||
cppbase::Result<bool, sqlitecpp::QueryError> check_exists(Object const * object, ExistsQueryData<T> const & query_data) {
|
||||
auto * object_type_str = ikarus_object_type_to_string(ikarus_id_get_object_type(object->id));
|
||||
|
||||
auto * ctx = object->project->get_function_context();
|
||||
|
||||
VTRY(
|
||||
auto exists,
|
||||
object->project->get_db()
|
||||
->template query_one<int>(
|
||||
fmt::format("SELECT EXISTS(SELECT 1 FROM `{}` WHERE `{}` = ?);", query_data.table_name, query_data.where_field_name),
|
||||
query_data.where_field_value
|
||||
)
|
||||
.on_error([&](auto const & err) {
|
||||
ctx->set_error(
|
||||
fmt::format("failed to check whether {} {} exists: {}", object_type_str, query_data.relation_desc, err),
|
||||
true,
|
||||
IkarusErrorInfo_Source_SubSystem,
|
||||
IkarusErrorInfo_Type_SubSystem_Database
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
return cppbase::ok(static_cast<bool>(exists));
|
||||
}
|
||||
|
||||
} // namespace ikarus::util
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue