update dependencies
This commit is contained in:
parent
e6233cf3f2
commit
ef27673846
21 changed files with 800 additions and 370 deletions
|
|
@ -2,8 +2,72 @@
|
|||
|
||||
#include <ikarus/errors.hpp>
|
||||
#include <ikarus/objects/blueprint.hpp>
|
||||
#include <ikarus/objects/entity.h>
|
||||
#include <ikarus/persistence/project.hpp>
|
||||
|
||||
IkarusBlueprint::IkarusBlueprint(struct IkarusProject * project, int64_t id):
|
||||
project{project},
|
||||
id{id} {}
|
||||
|
||||
IkarusBlueprint * ikarus_blueprint_create(
|
||||
struct IkarusProject * project,
|
||||
char const * name,
|
||||
IkarusBlueprintCreateFlags flags,
|
||||
struct IkarusErrorData * error_out
|
||||
) {
|
||||
IKARUS_FAIL_IF_NULL(project, nullptr);
|
||||
IKARUS_FAIL_IF_NAME_INVALID(name, nullptr);
|
||||
|
||||
IKARUS_TRYRV_OR_FAIL(
|
||||
nullptr,
|
||||
"failed to create entity: {}",
|
||||
IkarusErrorInfo_Database_QueryFailed,
|
||||
project->db->execute("INSERT INTO `blueprints`(`name`) VALUES(?)", name)
|
||||
);
|
||||
|
||||
auto const id = project->db->last_insert_rowid();
|
||||
return new IkarusBlueprint{project, id};
|
||||
}
|
||||
|
||||
IkarusBlueprint * ikarus_blueprint_create_from_entity(
|
||||
struct IkarusEntity * entity,
|
||||
char const * name,
|
||||
IkarusBlueprintCreateFromEntityFlags flags,
|
||||
struct IkarusErrorData * error_out
|
||||
) {
|
||||
IKARUS_TRYRV_OR_FAIL(
|
||||
nullptr,
|
||||
"{}",
|
||||
IkarusErrorInfo_Database_QueryFailed,
|
||||
ikarus_libikarus_func_call_to_result(
|
||||
error_out,
|
||||
ikarus_must_return_true(ikarus_entity_exists, "entity doesn't exist", IkarusErrorInfo_Client_NonExistent),
|
||||
entity
|
||||
)
|
||||
);
|
||||
IKARUS_FAIL_IF_NAME_INVALID(name, nullptr);
|
||||
|
||||
IKARUS_VTRYRV_OR_FAIL(
|
||||
auto id,
|
||||
nullptr,
|
||||
"failed to create blueprint from entity: {}",
|
||||
IkarusErrorInfo_Database_QueryFailed,
|
||||
entity->project->db->transact([&](auto * db) -> cppbase::Result<int64_t, sqlitecpp::TransactionError> {
|
||||
CPPBASE_TRY(db->execute("INSERT INTO `blueprints`(`name`) VALUES(?)", name));
|
||||
|
||||
auto const id = db->last_insert_rowid();
|
||||
|
||||
CPPBASE_TRY(entity->project->db->execute(
|
||||
"INSERT INTO `properties`(`blueprint`, `name`, `schema`) "
|
||||
"SELECT ?, `name`, json_extract(`value`, '$.schema') FROM `entity_values` "
|
||||
"WHERE `entity` = ?",
|
||||
id,
|
||||
entity->id
|
||||
))
|
||||
|
||||
return cppbase::ok(entity->project->db->last_insert_rowid());
|
||||
})
|
||||
);
|
||||
|
||||
return new IkarusBlueprint{entity->project, id};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue