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
192
clang-format.txt
Normal file
192
clang-format.txt
Normal file
|
|
@ -0,0 +1,192 @@
|
||||||
|
BasedOnStyle: Google
|
||||||
|
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
|
||||||
|
AlignAfterOpenBracket: BlockIndent
|
||||||
|
AlignArrayOfStructures: Right
|
||||||
|
AlignConsecutiveAssignments:
|
||||||
|
Enabled: false
|
||||||
|
AlignConsecutiveBitFields:
|
||||||
|
Enabled: false
|
||||||
|
AlignConsecutiveDeclarations:
|
||||||
|
Enabled: false
|
||||||
|
AlignConsecutiveMacros: AcrossEmptyLines
|
||||||
|
AlignEscapedNewlines: Left
|
||||||
|
AlignOperands: Align
|
||||||
|
AlignTrailingComments: true
|
||||||
|
|
||||||
|
AllowAllArgumentsOnNextLine: false
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
|
AllowShortBlocksOnASingleLine: Empty
|
||||||
|
AllowShortCaseLabelsOnASingleLine: true
|
||||||
|
AllowShortEnumsOnASingleLine: true
|
||||||
|
AllowShortFunctionsOnASingleLine: Empty
|
||||||
|
AllowShortIfStatementsOnASingleLine: WithoutElse
|
||||||
|
AllowShortLambdasOnASingleLine: All
|
||||||
|
AllowShortLoopsOnASingleLine: true
|
||||||
|
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
AlwaysBreakBeforeMultilineStrings: true
|
||||||
|
AlwaysBreakTemplateDeclarations: Yes
|
||||||
|
|
||||||
|
BinPackArguments: false
|
||||||
|
BinPackParameters: false
|
||||||
|
|
||||||
|
BitFieldColonSpacing: Both
|
||||||
|
|
||||||
|
BraceWrapping:
|
||||||
|
AfterCaseLabel: false
|
||||||
|
AfterClass: false
|
||||||
|
AfterControlStatement: Never
|
||||||
|
AfterEnum: false
|
||||||
|
AfterFunction: false
|
||||||
|
AfterNamespace: false
|
||||||
|
AfterStruct: false
|
||||||
|
AfterUnion: false
|
||||||
|
AfterExternBlock: false
|
||||||
|
BeforeCatch: false
|
||||||
|
BeforeElse: false
|
||||||
|
BeforeLambdaBody: false
|
||||||
|
BeforeWhile: false
|
||||||
|
IndentBraces: false
|
||||||
|
SplitEmptyFunction: false
|
||||||
|
SplitEmptyNamespace: false
|
||||||
|
SplitEmptyRecord: false
|
||||||
|
|
||||||
|
BracedInitializerIndentWidth: 4
|
||||||
|
|
||||||
|
# BreakAdjacentStringLiterals: true
|
||||||
|
BreakAfterAttributes: Never
|
||||||
|
BreakBeforeBinaryOperators: None
|
||||||
|
BreakBeforeBraces: Custom
|
||||||
|
BreakBeforeConceptDeclarations: Always
|
||||||
|
BreakBeforeInlineASMColon: OnlyMultiline
|
||||||
|
BreakBeforeTernaryOperators: false
|
||||||
|
BreakConstructorInitializers: AfterColon
|
||||||
|
BreakInheritanceList: AfterColon
|
||||||
|
BreakStringLiterals: false
|
||||||
|
|
||||||
|
ColumnLimit: 140
|
||||||
|
|
||||||
|
CompactNamespaces: false
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
|
||||||
|
EmptyLineAfterAccessModifier: Never
|
||||||
|
EmptyLineBeforeAccessModifier: Always
|
||||||
|
|
||||||
|
ExperimentalAutoDetectBinPacking: true
|
||||||
|
|
||||||
|
FixNamespaceComments: true
|
||||||
|
|
||||||
|
IncludeBlocks: Regroup
|
||||||
|
IncludeCategories:
|
||||||
|
- Regex: '^".+\.(h|hpp)"$'
|
||||||
|
Priority: 1
|
||||||
|
- Regex: '^<[a-z0-9_]+\.h>$'
|
||||||
|
Priority: 2
|
||||||
|
- Regex: '^<[a-z0-9_]+>$'
|
||||||
|
Priority: 3
|
||||||
|
- Regex: '^<boost/.*>$'
|
||||||
|
Priority: 4
|
||||||
|
- Regex: '^<expected/.*>$'
|
||||||
|
Priority: 5
|
||||||
|
- Regex: '^<fmt/.*>$'
|
||||||
|
Priority: 6
|
||||||
|
- Regex: '^<nlohmann/.*>$'
|
||||||
|
Priority: 7
|
||||||
|
- Regex: '^<range-v3/.*>$'
|
||||||
|
Priority: 8
|
||||||
|
- Regex: '^<catch2/.*>$'
|
||||||
|
Priority: 9
|
||||||
|
- Regex: '^<unicode/.*>$'
|
||||||
|
Priority: 10
|
||||||
|
- Regex: '^<cppbase/.*>$'
|
||||||
|
Priority: 11
|
||||||
|
- Regex: '^<sqlitecpp/.*>$'
|
||||||
|
Priority: 12
|
||||||
|
- Regex: '^<ikarus/.*>$'
|
||||||
|
Priority: 13
|
||||||
|
|
||||||
|
IndentAccessModifiers: false
|
||||||
|
IndentCaseBlocks: false
|
||||||
|
IndentCaseLabels: false
|
||||||
|
IndentExternBlock: NoIndent
|
||||||
|
IndentGotoLabels: false
|
||||||
|
IndentPPDirectives: None
|
||||||
|
IndentRequiresClause: true
|
||||||
|
IndentWidth: 4
|
||||||
|
IndentWrappedFunctionNames: false
|
||||||
|
InsertBraces: true
|
||||||
|
InsertNewlineAtEOF: true
|
||||||
|
InsertTrailingCommas: Wrapped
|
||||||
|
|
||||||
|
IntegerLiteralSeparator:
|
||||||
|
Binary: -1
|
||||||
|
Decimal: 3
|
||||||
|
Hex: -1
|
||||||
|
|
||||||
|
KeepEmptyLinesAtEOF: false
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
|
|
||||||
|
LambdaBodyIndentation: Signature
|
||||||
|
Language: Cpp
|
||||||
|
|
||||||
|
LineEnding: LF
|
||||||
|
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
|
||||||
|
NamespaceIndentation: None
|
||||||
|
|
||||||
|
PPIndentWidth: -1
|
||||||
|
PackConstructorInitializers: Never
|
||||||
|
|
||||||
|
PointerAlignment: Middle
|
||||||
|
QualifierAlignment: Right
|
||||||
|
# QualifierOrder: [ 'friend', 'constexpr', 'inline', 'static', 'type', 'const', 'volatile' ]
|
||||||
|
ReferenceAlignment: Middle
|
||||||
|
|
||||||
|
ReflowComments: true
|
||||||
|
RemoveBracesLLVM: false
|
||||||
|
RemoveParentheses: MultipleParentheses
|
||||||
|
RemoveSemicolon: true
|
||||||
|
|
||||||
|
RequiresClausePosition: OwnLine
|
||||||
|
RequiresExpressionIndentation: OuterScope
|
||||||
|
|
||||||
|
SeparateDefinitionBlocks: Always
|
||||||
|
|
||||||
|
SortIncludes: CaseInsensitive
|
||||||
|
SortUsingDeclarations: LexicographicNumeric
|
||||||
|
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
SpaceAfterLogicalNot: false
|
||||||
|
SpaceAfterTemplateKeyword: false
|
||||||
|
SpaceAroundPointerQualifiers: Both
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeCaseColon: false
|
||||||
|
SpaceBeforeCpp11BracedList: false
|
||||||
|
SpaceBeforeCtorInitializerColon: false
|
||||||
|
SpaceBeforeInheritanceColon: true
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceBeforeRangeBasedForLoopColon: true
|
||||||
|
SpaceBeforeSquareBrackets: false
|
||||||
|
SpaceInEmptyBlock: false
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
SpacesInAngles: false
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpacesInConditionalStatement: false
|
||||||
|
SpacesInContainerLiterals: false
|
||||||
|
SpacesInLineCommentPrefix:
|
||||||
|
Minimum: 1
|
||||||
|
Maximum: 1
|
||||||
|
SpacesInParentheses: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
Standard: c++20
|
||||||
|
|
||||||
|
TabWidth: 4
|
||||||
|
UseTab: Never
|
||||||
|
|
@ -27,7 +27,7 @@ IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char c
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_blueprint_delete(IkarusBlueprint * blueprint) {
|
void ikarus_blueprint_delete(IkarusBlueprint * blueprint) {
|
||||||
ikarus::util::delete_object(blueprint->project, blueprint);
|
ikarus::util::delete_object(blueprint);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_blueprint_get_properties(
|
void ikarus_blueprint_get_properties(
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,36 @@
|
||||||
|
|
||||||
#include <cppbase/strings.hpp>
|
#include <cppbase/strings.hpp>
|
||||||
|
|
||||||
|
#include <objects/blueprint.hpp>
|
||||||
|
#include <objects/util.hpp>
|
||||||
#include <persistence/function_context.hpp>
|
#include <persistence/function_context.hpp>
|
||||||
#include <persistence/project.hpp>
|
#include <persistence/project.hpp>
|
||||||
|
|
||||||
IkarusEntity * ikarus_entity_create(struct IkarusProject * project, char const * name) {
|
IkarusEntity * ikarus_entity_create(struct IkarusProject * project, char const * name) {
|
||||||
LOG_INFO("creating new entity");
|
return ikarus::util::insert_object(
|
||||||
|
project,
|
||||||
LOG_DEBUG("project={}; name={}", project->get_path().c_str(), name);
|
IkarusObjectType_Entity,
|
||||||
|
name,
|
||||||
auto * ctx = project->get_function_context();
|
[](auto * db, IkarusId id) { return db->execute("INSERT INTO `entities`(`id`) VALUES(?)", id); },
|
||||||
|
[project](IkarusId id) { return project->get_entity(id); }
|
||||||
if (cppbase::is_empty_or_blank(name)) {
|
).unwrap_value_or(nullptr);
|
||||||
ctx->set_error("name is empty or blank", true, IkarusErrorInfo_Source_Client, IkarusErrorInfo_Type_Client_Input);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
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();
|
auto * ctx = project->get_function_context();
|
||||||
|
|
||||||
VTRY(
|
VTRY(
|
||||||
|
|
@ -45,10 +41,6 @@ cppbase::Result<IkarusPropertyType, sqlitecpp::SingleQueryError> IkarusProperty:
|
||||||
}
|
}
|
||||||
|
|
||||||
IKA_API void ikarus_property_delete(IkarusProperty * property) {
|
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();
|
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) {
|
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);
|
property->project->uncache(property);
|
||||||
|
|
||||||
LOG_VERBOSE("successfully deleted property");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IkarusPropertyType ikarus_property_get_type(IkarusProperty const * 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);
|
return IkarusProperty::get_property_type(property->project, property->id).unwrap_value_or(IkarusPropertyType_Toggle);
|
||||||
}
|
}
|
||||||
|
|
||||||
IkarusPropertySource const * ikarus_property_get_source(IkarusProperty const * property) {
|
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();
|
auto * ctx = property->project->get_function_context();
|
||||||
|
|
||||||
VTRYRV(
|
VTRYRV(
|
||||||
|
|
@ -112,10 +94,6 @@ IkarusPropertySource const * ikarus_property_get_source(IkarusProperty const * p
|
||||||
}
|
}
|
||||||
|
|
||||||
IkarusValue * ikarus_property_get_default_value(IkarusProperty const * property) {
|
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();
|
auto * ctx = property->project->get_function_context();
|
||||||
|
|
||||||
VTRYRV(
|
VTRYRV(
|
||||||
|
|
|
||||||
|
|
@ -28,10 +28,6 @@ template<typename InsertFunction, typename ObjectFactory>
|
||||||
) {
|
) {
|
||||||
auto const * object_type_str = ikarus_object_type_to_string(type);
|
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();
|
auto * ctx = project->get_function_context();
|
||||||
|
|
||||||
if (cppbase::is_empty_or_blank(name)) {
|
if (cppbase::is_empty_or_blank(name)) {
|
||||||
|
|
@ -43,14 +39,10 @@ template<typename InsertFunction, typename ObjectFactory>
|
||||||
auto const id,
|
auto const id,
|
||||||
project->get_db()
|
project->get_db()
|
||||||
->transact([&](auto * db) -> cppbase::Result<IkarusId, sqlitecpp::TransactionError> {
|
->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));
|
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);
|
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));
|
TRY(insert_function(db, id));
|
||||||
|
|
||||||
return cppbase::ok(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));
|
return cppbase::ok(object_factory(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Object>
|
template<typename Object>
|
||||||
requires std::derived_from<Object, IkarusObject>
|
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));
|
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();
|
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(
|
ctx->set_error(
|
||||||
fmt::format("failed to delete {} from objects table: {}", object_type_str, err),
|
fmt::format("failed to delete {} from objects table: {}", object_type_str, err),
|
||||||
true,
|
true,
|
||||||
|
|
@ -90,11 +76,7 @@ void delete_object(IkarusProject * project, Object * object) {
|
||||||
);
|
);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
LOG_VERBOSE("{} was successfully deleted from database, freeing", object_type_str);
|
object->project->uncache(object);
|
||||||
|
|
||||||
project->uncache(object);
|
|
||||||
|
|
||||||
LOG_VERBOSE("successfully deleted {}", object_type_str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SingleQueryData {
|
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) {
|
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));
|
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();
|
auto * ctx = object->project->get_function_context();
|
||||||
|
|
||||||
VTRY(
|
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));
|
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];
|
Selected select_buffer[buffer_size];
|
||||||
|
|
||||||
TRYRV(
|
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) {
|
for (size_t i = 0; i < buffer_size; ++i) {
|
||||||
VTRYRV(mapped_buffer[i], , transformer(object->project, ctx, select_buffer[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) {
|
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));
|
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();
|
auto * ctx = object->project->get_function_context();
|
||||||
|
|
||||||
LOG_DEBUG("{}={}", object_type_str, object->id);
|
|
||||||
|
|
||||||
VTRY(
|
VTRY(
|
||||||
auto count,
|
auto count,
|
||||||
object->project->get_db()
|
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));
|
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
|
} // namespace ikarus::util
|
||||||
|
|
|
||||||
2
vendor/sqlitecpp
vendored
2
vendor/sqlitecpp
vendored
|
|
@ -1 +1 @@
|
||||||
Subproject commit 2a93b8b1a8be03a9a9c4c72956b1111299de0ddd
|
Subproject commit 00a1afcc5f564f562c436f1ddfa4f44bb6489b17
|
||||||
Loading…
Add table
Add a link
Reference in a new issue