implement ikarus_project_get_*_by_name functions
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
4fe97b13cb
commit
c66489d178
6 changed files with 80 additions and 19 deletions
|
|
@ -10,6 +10,7 @@
|
|||
#include <ikarus/objects/properties/property.hpp>
|
||||
#include <ikarus/objects/properties/text_property.hpp>
|
||||
#include <ikarus/objects/properties/toggle_property.hpp>
|
||||
#include <ikarus/objects/util.hpp>
|
||||
#include <ikarus/persistence/migrations.hpp>
|
||||
#include <ikarus/persistence/project.hpp>
|
||||
|
||||
|
|
@ -275,3 +276,60 @@ size_t ikarus_project_get_entity_count(IkarusProject * project, IkarusErrorData
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct IkarusEntity * get_entity_by_name(IkarusProject * project, char const * name, IkarusErrorData * error_out) {
|
||||
IKARUS_FAIL_IF_NULL(project, nullptr);
|
||||
IKARUS_FAIL_IF_NULL(name, nullptr);
|
||||
IKARUS_FAIL_IF_NAME_INVALID(name, nullptr);
|
||||
|
||||
// TODO, 'InvalidInput' doesn't really make sense here, we'd need to adjust the macros to support distinguishing between different
|
||||
// errors. In this case `sqlitecpp::MissingRow` and database related errors. Same for the other functions.
|
||||
IKARUS_VTRYRV_OR_FAIL(
|
||||
auto const id,
|
||||
nullptr,
|
||||
"unable to find entity in database: {}",
|
||||
IkarusErrorInfo_Client_InvalidInput,
|
||||
project->db->query_one<IkarusId>("SELECT `id` FROM `entities` WHERE `name` = ?", name)
|
||||
);
|
||||
|
||||
return project->get_entity(id);
|
||||
}
|
||||
|
||||
struct IkarusProperty *
|
||||
get_property_by_name(IkarusProject * project, IkarusPropertyScope * scope, char const * name, IkarusErrorData * error_out) {
|
||||
IKARUS_FAIL_IF_NULL(project, nullptr);
|
||||
IKARUS_FAIL_IF_NULL(name, nullptr);
|
||||
IKARUS_FAIL_IF_NAME_INVALID(name, nullptr);
|
||||
|
||||
IKARUS_VTRYRV_OR_FAIL(
|
||||
auto const id_and_type,
|
||||
nullptr,
|
||||
"unable to find property in database: {}",
|
||||
IkarusErrorInfo_Client_InvalidInput,
|
||||
project->db->query_one<IkarusId, IkarusPropertyType>(
|
||||
"SELECT `id`, `type` FROM `properties` WHERE `name` = ? AND `scope` = ?",
|
||||
name,
|
||||
scope->get_id()
|
||||
)
|
||||
);
|
||||
|
||||
auto const [id, type] = id_and_type;
|
||||
|
||||
return project->get_property(id, type);
|
||||
}
|
||||
|
||||
IkarusBlueprint * get_blueprints_by_name(IkarusProject * project, char const * name, IkarusErrorData * error_out) {
|
||||
IKARUS_FAIL_IF_NULL(project, nullptr);
|
||||
IKARUS_FAIL_IF_NULL(name, nullptr);
|
||||
IKARUS_FAIL_IF_NAME_INVALID(name, nullptr);
|
||||
|
||||
IKARUS_VTRYRV_OR_FAIL(
|
||||
auto const id,
|
||||
nullptr,
|
||||
"unable to find blueprint in database: {}",
|
||||
IkarusErrorInfo_Client_InvalidInput,
|
||||
project->db->query_one<IkarusId>("SELECT `id` FROM `blueprints` WHERE `name` = ?", name)
|
||||
);
|
||||
|
||||
return project->get_blueprint(id);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue