add flatbuffers support and initial rewrite
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
7e883d24eb
commit
98cb7a44ef
72 changed files with 3929 additions and 1403 deletions
|
|
@ -11,24 +11,27 @@
|
|||
#include <ikarus/objects/properties/property.hpp>
|
||||
#include <ikarus/objects/util.hpp>
|
||||
#include <ikarus/persistence/project.hpp>
|
||||
#include <ikarus/values/value_type.h>
|
||||
|
||||
IkarusBlueprint::IkarusBlueprint(IkarusProject * project, IkarusId id):
|
||||
IkarusBlueprint::IkarusBlueprint(IkarusProject * project, int64_t id):
|
||||
IkarusObject{project, id} {}
|
||||
|
||||
std::string_view IkarusBlueprint::get_table_name() const noexcept {
|
||||
return "blueprints";
|
||||
}
|
||||
|
||||
IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char const * name, IkarusErrorData * error_out) {
|
||||
IKARUS_FAIL_IF_NULL(project, nullptr);
|
||||
IKARUS_FAIL_IF_NAME_INVALID_OR_DUPLICATE(name, project, static_cast<IkarusEntity const *>(nullptr), nullptr);
|
||||
IKARUS_FAIL_IF_NAME_INVALID(name, nullptr);
|
||||
|
||||
IKARUS_VTRYRV_OR_FAIL(
|
||||
IkarusId const id,
|
||||
int64_t const id,
|
||||
nullptr,
|
||||
"failed to create blueprint: {}",
|
||||
IkarusErrorInfo_Database_QueryFailed,
|
||||
project->db->transact([name](auto * db) -> cppbase::Result<IkarusId, sqlitecpp::TransactionError> {
|
||||
TRY(db->execute("INSERT INTO `objects`(`type`) VALUES(?)", IkarusObjectType_Blueprint));
|
||||
auto id = ikarus_id_from_data_and_type(db->last_insert_rowid(), IkarusObjectType_Blueprint);
|
||||
TRY(db->execute("INSERT INTO `blueprints`(`id`, `name`) VALUES(?, ?)", id, name));
|
||||
return cppbase::ok(id);
|
||||
project->db->transact([name](auto * db) -> cppbase::Result<int64_t, sqlitecpp::TransactionError> {
|
||||
TRY(db->execute("INSERT INTO `blueprints`(`name`) VALUES(?)", name));
|
||||
return cppbase::ok(db->last_insert_rowid());
|
||||
})
|
||||
);
|
||||
|
||||
|
|
@ -43,13 +46,13 @@ void ikarus_blueprint_delete(IkarusBlueprint * blueprint, IkarusErrorData * erro
|
|||
,
|
||||
"unable to delete blueprint: {}",
|
||||
IkarusErrorInfo_Database_QueryFailed,
|
||||
blueprint->project->db->execute("DELETE FROM `objects` WHERE `id` = ?", blueprint->id)
|
||||
blueprint->project->db->execute("DELETE FROM `blueprints` WHERE `id` = ?", blueprint->id)
|
||||
);
|
||||
|
||||
blueprint->project->uncache(blueprint);
|
||||
}
|
||||
|
||||
IkarusId ikarus_blueprint_get_id(IkarusBlueprint const * blueprint, IkarusErrorData * error_out) {
|
||||
int64_t ikarus_blueprint_get_id(IkarusBlueprint const * blueprint, IkarusErrorData * error_out) {
|
||||
return ikarus::util::object_get_id(blueprint, error_out);
|
||||
}
|
||||
|
||||
|
|
@ -79,14 +82,14 @@ void ikarus_blueprint_get_properties(
|
|||
return;
|
||||
}
|
||||
|
||||
std::tuple<IkarusId, IkarusPropertyType> ids_and_types[properties_out_size];
|
||||
std::tuple<int64_t, IkarusValueType> ids_and_types[properties_out_size];
|
||||
|
||||
IKARUS_TRYRV_OR_FAIL(
|
||||
,
|
||||
"unable to fetch blueprint properties from database: {}",
|
||||
IkarusErrorInfo_Database_QueryFailed,
|
||||
blueprint->project->db->query_many_buffered<IkarusId, IkarusPropertyType>(
|
||||
"SELECT `id` FROM `properties` WHERE `source` = ?",
|
||||
blueprint->project->db->query_many_buffered<int64_t, IkarusValueType>(
|
||||
"SELECT `id` FROM `properties` WHERE `blueprint` = ?",
|
||||
ids_and_types,
|
||||
properties_out_size,
|
||||
blueprint->id
|
||||
|
|
@ -109,7 +112,7 @@ size_t ikarus_blueprint_get_property_count(IkarusBlueprint const * blueprint, Ik
|
|||
0,
|
||||
"unable to fetch blueprint property count from database: {}",
|
||||
IkarusErrorInfo_Database_QueryFailed,
|
||||
blueprint->project->db->query_one<int64_t>("SELECT COUNT(*) FROM `properties` WHERE `source` = ?", blueprint->id)
|
||||
blueprint->project->db->query_one<int64_t>("SELECT COUNT(*) FROM `properties` WHERE `blueprint` = ?", blueprint->id)
|
||||
);
|
||||
|
||||
return ret;
|
||||
|
|
@ -129,13 +132,13 @@ void ikarus_blueprint_get_linked_entities(
|
|||
return;
|
||||
}
|
||||
|
||||
IkarusId ids[entities_out_size];
|
||||
int64_t ids[entities_out_size];
|
||||
|
||||
IKARUS_TRYRV_OR_FAIL(
|
||||
,
|
||||
"unable to fetch blueprint linked entities from database: {}",
|
||||
IkarusErrorInfo_Database_QueryFailed,
|
||||
blueprint->project->db->query_many_buffered<IkarusId>(
|
||||
blueprint->project->db->query_many_buffered<int64_t>(
|
||||
"SELECT `entity` FROM `entity_blueprint_links` WHERE `blueprint` = ?",
|
||||
ids,
|
||||
entities_out_size,
|
||||
|
|
@ -157,7 +160,8 @@ size_t ikarus_blueprint_get_linked_entity_count(IkarusBlueprint const * blueprin
|
|||
0,
|
||||
"unable to fetch blueprint linked entity count from database: {}",
|
||||
IkarusErrorInfo_Database_QueryFailed,
|
||||
blueprint->project->db->query_one<int64_t>("SELECT COUNT(*) FROM `entity_blueprint_links` WHERE `blueprint` = ?", blueprint->id)
|
||||
blueprint->project->db
|
||||
->query_one<int64_t>("SELECT COUNT(`entity`) FROM `entity_blueprint_links` WHERE `blueprint` = ?", blueprint->id)
|
||||
);
|
||||
|
||||
return ret;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue