From 58a6cab0ebdb89ed7f1febe67599ac9d7757b684 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 15:27:21 -0300 Subject: [PATCH 01/12] update --- include/psr/attribute_type.h | 4 ++-- include/psr/column_type.h | 35 ----------------------------------- include/psr/data_type.h | 35 +++++++++++++++++++++++++++++++++++ include/psr/schema.h | 8 ++++---- 4 files changed, 41 insertions(+), 41 deletions(-) delete mode 100644 include/psr/column_type.h create mode 100644 include/psr/data_type.h diff --git a/include/psr/attribute_type.h b/include/psr/attribute_type.h index 96372d3..4dee4aa 100644 --- a/include/psr/attribute_type.h +++ b/include/psr/attribute_type.h @@ -1,16 +1,16 @@ #ifndef PSR_ATTRIBUTE_TYPE_H #define PSR_ATTRIBUTE_TYPE_H +#include "data_type.h" #include "export.h" namespace psr { enum class AttributeStructure { Scalar, Vector, Set }; -enum class AttributeDataType { Integer, Real, Text }; struct PSR_API AttributeType { AttributeStructure structure; - AttributeDataType data_type; + DataType data_type; }; } // namespace psr diff --git a/include/psr/column_type.h b/include/psr/column_type.h deleted file mode 100644 index 8c7fa00..0000000 --- a/include/psr/column_type.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef PSR_COLUMN_TYPE_H -#define PSR_COLUMN_TYPE_H - -#include -#include - -namespace psr { - -enum class ColumnType { Integer, Real, Text }; - -inline ColumnType column_type_from_string(const std::string& type_str) { - if (type_str == "INTEGER") - return ColumnType::Integer; - else if (type_str == "REAL") - return ColumnType::Real; - else if (type_str == "TEXT") - return ColumnType::Text; - throw std::runtime_error("Unknown column type: " + type_str); -} - -inline const char* column_type_to_string(ColumnType type) { - switch (type) { - case ColumnType::Integer: - return "INTEGER"; - case ColumnType::Real: - return "REAL"; - case ColumnType::Text: - return "TEXT"; - } - return "UNKNOWN"; -} - -} // namespace psr - -#endif // PSR_COLUMN_TYPE_H diff --git a/include/psr/data_type.h b/include/psr/data_type.h new file mode 100644 index 0000000..693dd7c --- /dev/null +++ b/include/psr/data_type.h @@ -0,0 +1,35 @@ +#ifndef PSR_DATA_TYPE_H +#define PSR_DATA_TYPE_H + +#include +#include + +namespace psr { + +enum class DataType { Integer, Real, Text }; + +inline DataType data_type_from_string(const std::string& type_str) { + if (type_str == "INTEGER") + return DataType::Integer; + else if (type_str == "REAL") + return DataType::Real; + else if (type_str == "TEXT") + return DataType::Text; + throw std::runtime_error("Unknown data type: " + type_str); +} + +inline const char* data_type_to_string(DataType type) { + switch (type) { + case DataType::Integer: + return "INTEGER"; + case DataType::Real: + return "REAL"; + case DataType::Text: + return "TEXT"; + } + return "UNKNOWN"; +} + +} // namespace psr + +#endif // PSR_DATA_TYPE_H diff --git a/include/psr/schema.h b/include/psr/schema.h index 046343a..c2c023e 100644 --- a/include/psr/schema.h +++ b/include/psr/schema.h @@ -1,7 +1,7 @@ #ifndef PSR_SCHEMA_H #define PSR_SCHEMA_H -#include "column_type.h" +#include "data_type.h" #include "export.h" #include @@ -15,7 +15,7 @@ namespace psr { struct ColumnDefinition { std::string name; - ColumnType type; + DataType type; bool not_null; bool primary_key; }; @@ -40,7 +40,7 @@ struct TableDefinition { std::vector foreign_keys; std::vector indexes; - std::optional get_column_type(const std::string& column) const; + std::optional get_column_type(const std::string& column) const; bool has_column(const std::string& column) const; const ColumnDefinition* get_column(const std::string& column) const; }; @@ -55,7 +55,7 @@ class PSR_API Schema { bool has_table(const std::string& name) const; // Column type lookup (throws if table/column not found) - ColumnType get_column_type(const std::string& table, const std::string& column) const; + DataType get_column_type(const std::string& table, const std::string& column) const; // Vector/Set table naming convention static std::string vector_table_name(const std::string& collection, const std::string& group); From ed06c24fcc27f298cf42d07c7ecd7d36106cc164 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 15:27:51 -0300 Subject: [PATCH 02/12] update --- include/psr/type_validator.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/psr/type_validator.h b/include/psr/type_validator.h index b19b53c..96d0ccb 100644 --- a/include/psr/type_validator.h +++ b/include/psr/type_validator.h @@ -1,7 +1,7 @@ #ifndef PSR_TYPE_VALIDATOR_H #define PSR_TYPE_VALIDATOR_H -#include "column_type.h" +#include "data_type.h" #include "export.h" #include "schema.h" #include "value.h" @@ -23,7 +23,7 @@ class PSR_API TypeValidator { void validate_array(const std::string& table, const std::string& column, const std::vector& values) const; // Low-level: validate value against explicit type - static void validate_value(const std::string& context, ColumnType expected_type, const Value& value); + static void validate_value(const std::string& context, DataType expected_type, const Value& value); private: const Schema& schema_; From 9509770917a99145002c4032a314046a3cb532bd Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 15:45:48 -0300 Subject: [PATCH 03/12] update --- include/psr/schema.h | 4 ++-- src/type_validator.cpp | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/psr/schema.h b/include/psr/schema.h index c2c023e..4c89cfd 100644 --- a/include/psr/schema.h +++ b/include/psr/schema.h @@ -40,7 +40,7 @@ struct TableDefinition { std::vector foreign_keys; std::vector indexes; - std::optional get_column_type(const std::string& column) const; + std::optional get_data_type(const std::string& column) const; bool has_column(const std::string& column) const; const ColumnDefinition* get_column(const std::string& column) const; }; @@ -55,7 +55,7 @@ class PSR_API Schema { bool has_table(const std::string& name) const; // Column type lookup (throws if table/column not found) - DataType get_column_type(const std::string& table, const std::string& column) const; + DataType get_data_type(const std::string& table, const std::string& column) const; // Vector/Set table naming convention static std::string vector_table_name(const std::string& collection, const std::string& group); diff --git a/src/type_validator.cpp b/src/type_validator.cpp index 8cb4091..8c03933 100644 --- a/src/type_validator.cpp +++ b/src/type_validator.cpp @@ -7,20 +7,20 @@ namespace psr { TypeValidator::TypeValidator(const Schema& schema) : schema_(schema) {} void TypeValidator::validate_scalar(const std::string& table, const std::string& column, const Value& value) const { - ColumnType expected = schema_.get_column_type(table, column); + auto expected = schema_.get_data_type(table, column); validate_value("column '" + column + "'", expected, value); } void TypeValidator::validate_array(const std::string& table, const std::string& column, const std::vector& values) const { - ColumnType expected = schema_.get_column_type(table, column); + auto expected = schema_.get_data_type(table, column); for (size_t i = 0; i < values.size(); ++i) { validate_value("array '" + column + "' index " + std::to_string(i), expected, values[i]); } } -void TypeValidator::validate_value(const std::string& context, ColumnType expected_type, const Value& value) { +void TypeValidator::validate_value(const std::string& context, DataType expected_type, const Value& value) { std::visit( [&](auto&& arg) { using T = std::decay_t; @@ -29,21 +29,21 @@ void TypeValidator::validate_value(const std::string& context, ColumnType expect // NULL allowed for any type return; } else if constexpr (std::is_same_v) { - if (expected_type != ColumnType::Integer) { + if (expected_type != DataType::Integer) { throw std::runtime_error("Type mismatch for " + context + ": expected " + - column_type_to_string(expected_type) + ", got INTEGER"); + data_type_to_string(expected_type) + ", got INTEGER"); } } else if constexpr (std::is_same_v) { // REAL can be stored in INTEGER or REAL columns - if (expected_type != ColumnType::Real && expected_type != ColumnType::Integer) { + if (expected_type != DataType::Real && expected_type != DataType::Integer) { throw std::runtime_error("Type mismatch for " + context + ": expected " + - column_type_to_string(expected_type) + ", got REAL"); + data_type_to_string(expected_type) + ", got REAL"); } } else if constexpr (std::is_same_v) { // String can go to TEXT or INTEGER (FK label resolution happens elsewhere) - if (expected_type != ColumnType::Text && expected_type != ColumnType::Integer) { + if (expected_type != DataType::Text && expected_type != DataType::Integer) { throw std::runtime_error("Type mismatch for " + context + ": expected " + - column_type_to_string(expected_type) + ", got TEXT"); + data_type_to_string(expected_type) + ", got TEXT"); } } }, From 3a83f13f3bea51828d472c3799273cf82c42d229 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 15:47:04 -0300 Subject: [PATCH 04/12] update --- src/database.cpp | 32 +++++++++----------------------- src/schema.cpp | 8 ++++---- src/schema_validator.cpp | 12 ++++++------ 3 files changed, 19 insertions(+), 33 deletions(-) diff --git a/src/database.cpp b/src/database.cpp index 72401bf..b7735b3 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -1376,25 +1376,11 @@ AttributeType Database::get_attribute_type(const std::string& collection, const throw std::runtime_error("Collection not found in schema: " + collection); } - // Helper to convert ColumnType to AttributeDataType - auto to_data_type = [](ColumnType ct) -> AttributeDataType { - switch (ct) { - case ColumnType::Integer: - return AttributeDataType::Integer; - case ColumnType::Real: - return AttributeDataType::Real; - case ColumnType::Text: - return AttributeDataType::Text; - default: - throw std::runtime_error("Unknown column type"); - } - }; - // Check if attribute exists as scalar (column on collection table) if (table_def->has_column(attribute)) { - auto col_type = table_def->get_column_type(attribute); - if (col_type) { - return AttributeType{AttributeStructure::Scalar, to_data_type(*col_type)}; + auto data_type = table_def->get_data_type(attribute); + if (data_type) { + return AttributeType{AttributeStructure::Scalar, *data_type}; } } @@ -1407,9 +1393,9 @@ AttributeType Database::get_attribute_type(const std::string& collection, const const auto* vec_table = impl_->schema->get_table(table_name); if (vec_table && vec_table->has_column(attribute)) { - auto col_type = vec_table->get_column_type(attribute); - if (col_type) { - return AttributeType{AttributeStructure::Vector, to_data_type(*col_type)}; + auto data_type = vec_table->get_data_type(attribute); + if (data_type) { + return AttributeType{AttributeStructure::Vector, *data_type}; } } } @@ -1423,9 +1409,9 @@ AttributeType Database::get_attribute_type(const std::string& collection, const const auto* set_table = impl_->schema->get_table(table_name); if (set_table && set_table->has_column(attribute)) { - auto col_type = set_table->get_column_type(attribute); - if (col_type) { - return AttributeType{AttributeStructure::Set, to_data_type(*col_type)}; + auto data_type = set_table->get_data_type(attribute); + if (data_type) { + return AttributeType{AttributeStructure::Set, *data_type}; } } } diff --git a/src/schema.cpp b/src/schema.cpp index 617e021..7411d68 100644 --- a/src/schema.cpp +++ b/src/schema.cpp @@ -7,7 +7,7 @@ namespace psr { // TableDefinition methods -std::optional TableDefinition::get_column_type(const std::string& column) const { +std::optional TableDefinition::get_data_type(const std::string& column) const { auto it = columns.find(column); if (it != columns.end()) { return it->second.type; @@ -49,12 +49,12 @@ bool Schema::has_table(const std::string& name) const { return tables_.find(name) != tables_.end(); } -ColumnType Schema::get_column_type(const std::string& table, const std::string& column) const { +DataType Schema::get_data_type(const std::string& table, const std::string& column) const { const auto* tbl = get_table(table); if (!tbl) { throw std::runtime_error("Table not found in schema: " + table); } - auto type = tbl->get_column_type(column); + auto type = tbl->get_data_type(column); if (!type) { throw std::runtime_error("Column '" + column + "' not found in table '" + table + "'"); } @@ -214,7 +214,7 @@ std::vector Schema::query_columns(sqlite3* db, const std::stri col.name = name ? name : ""; std::string type_str = type ? type : ""; - col.type = column_type_from_string(type_str); + col.type = data_type_from_string(type_str); col.not_null = sqlite3_column_int(stmt, 3) != 0; col.primary_key = sqlite3_column_int(stmt, 5) != 0; diff --git a/src/schema_validator.cpp b/src/schema_validator.cpp index 0407635..60bca1e 100644 --- a/src/schema_validator.cpp +++ b/src/schema_validator.cpp @@ -67,20 +67,20 @@ void SchemaValidator::validate_collection(const std::string& name) { } // Must have 'id' column as primary key - const auto* id_col = table->get_column("id"); - if (!id_col || !id_col->primary_key) { + const auto* id_column = table->get_column("id"); + if (!id_column || !id_column->primary_key) { validation_error("Collection '" + name + "' must have 'id' as primary key"); } // Must have 'label' column with TEXT type and NOT NULL constraint - const auto* label_col = table->get_column("label"); - if (!label_col) { + const auto* label_column = table->get_column("label"); + if (!label_column) { validation_error("Collection '" + name + "' must have a 'label' column"); } - if (label_col->type != ColumnType::Text) { + if (label_column->type != DataType::Text) { validation_error("Collection '" + name + "' label column must be TEXT type"); } - if (!label_col->not_null) { + if (!label_column->not_null) { validation_error("Collection '" + name + "' label column must have NOT NULL constraint"); } From db95a64cacedea9268c7cfcc3cfae6388fc821fc Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 15:47:28 -0300 Subject: [PATCH 05/12] update --- src/c_api_database.cpp | 6 +++--- tests/test_database_read.cpp | 12 ++++++------ tests/test_schema_validator.cpp | 20 ++++++++++---------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/c_api_database.cpp b/src/c_api_database.cpp index 1bfe783..cf55927 100644 --- a/src/c_api_database.cpp +++ b/src/c_api_database.cpp @@ -905,13 +905,13 @@ PSR_C_API psr_error_t psr_database_get_attribute_type(psr_database_t* db, } switch (attr_type.data_type) { - case psr::AttributeDataType::Integer: + case psr::DataType::Integer: *out_data_type = PSR_DATA_TYPE_INTEGER; break; - case psr::AttributeDataType::Real: + case psr::DataType::Real: *out_data_type = PSR_DATA_TYPE_REAL; break; - case psr::AttributeDataType::Text: + case psr::DataType::Text: *out_data_type = PSR_DATA_TYPE_TEXT; break; } diff --git a/tests/test_database_read.cpp b/tests/test_database_read.cpp index 6799c4a..e86f7bd 100644 --- a/tests/test_database_read.cpp +++ b/tests/test_database_read.cpp @@ -479,7 +479,7 @@ TEST(Database, GetAttributeTypeScalarInteger) { auto attr_type = db.get_attribute_type("Configuration", "integer_attribute"); EXPECT_EQ(attr_type.structure, psr::AttributeStructure::Scalar); - EXPECT_EQ(attr_type.data_type, psr::AttributeDataType::Integer); + EXPECT_EQ(attr_type.data_type, psr::DataType::Integer); } TEST(Database, GetAttributeTypeScalarReal) { @@ -487,7 +487,7 @@ TEST(Database, GetAttributeTypeScalarReal) { auto attr_type = db.get_attribute_type("Configuration", "float_attribute"); EXPECT_EQ(attr_type.structure, psr::AttributeStructure::Scalar); - EXPECT_EQ(attr_type.data_type, psr::AttributeDataType::Real); + EXPECT_EQ(attr_type.data_type, psr::DataType::Real); } TEST(Database, GetAttributeTypeScalarText) { @@ -495,7 +495,7 @@ TEST(Database, GetAttributeTypeScalarText) { auto attr_type = db.get_attribute_type("Configuration", "string_attribute"); EXPECT_EQ(attr_type.structure, psr::AttributeStructure::Scalar); - EXPECT_EQ(attr_type.data_type, psr::AttributeDataType::Text); + EXPECT_EQ(attr_type.data_type, psr::DataType::Text); } TEST(Database, GetAttributeTypeVectorInteger) { @@ -504,7 +504,7 @@ TEST(Database, GetAttributeTypeVectorInteger) { auto attr_type = db.get_attribute_type("Collection", "value_int"); EXPECT_EQ(attr_type.structure, psr::AttributeStructure::Vector); - EXPECT_EQ(attr_type.data_type, psr::AttributeDataType::Integer); + EXPECT_EQ(attr_type.data_type, psr::DataType::Integer); } TEST(Database, GetAttributeTypeVectorReal) { @@ -513,7 +513,7 @@ TEST(Database, GetAttributeTypeVectorReal) { auto attr_type = db.get_attribute_type("Collection", "value_float"); EXPECT_EQ(attr_type.structure, psr::AttributeStructure::Vector); - EXPECT_EQ(attr_type.data_type, psr::AttributeDataType::Real); + EXPECT_EQ(attr_type.data_type, psr::DataType::Real); } TEST(Database, GetAttributeTypeSetText) { @@ -522,7 +522,7 @@ TEST(Database, GetAttributeTypeSetText) { auto attr_type = db.get_attribute_type("Collection", "tag"); EXPECT_EQ(attr_type.structure, psr::AttributeStructure::Set); - EXPECT_EQ(attr_type.data_type, psr::AttributeDataType::Text); + EXPECT_EQ(attr_type.data_type, psr::DataType::Text); } TEST(Database, GetAttributeTypeNotFound) { diff --git a/tests/test_schema_validator.cpp b/tests/test_schema_validator.cpp index 61a4ef9..ed31aaf 100644 --- a/tests/test_schema_validator.cpp +++ b/tests/test_schema_validator.cpp @@ -126,7 +126,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeScalarInteger) { auto type = db.get_attribute_type("Configuration", "integer_attribute"); EXPECT_EQ(type.structure, psr::AttributeStructure::Scalar); - EXPECT_EQ(type.data_type, psr::AttributeDataType::Integer); + EXPECT_EQ(type.data_type, psr::DataType::Integer); } TEST_F(SchemaValidatorFixture, GetAttributeTypeScalarReal) { @@ -135,7 +135,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeScalarReal) { auto type = db.get_attribute_type("Configuration", "float_attribute"); EXPECT_EQ(type.structure, psr::AttributeStructure::Scalar); - EXPECT_EQ(type.data_type, psr::AttributeDataType::Real); + EXPECT_EQ(type.data_type, psr::DataType::Real); } TEST_F(SchemaValidatorFixture, GetAttributeTypeScalarText) { @@ -144,7 +144,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeScalarText) { auto type = db.get_attribute_type("Configuration", "label"); EXPECT_EQ(type.structure, psr::AttributeStructure::Scalar); - EXPECT_EQ(type.data_type, psr::AttributeDataType::Text); + EXPECT_EQ(type.data_type, psr::DataType::Text); } TEST_F(SchemaValidatorFixture, GetAttributeTypeVectorInteger) { @@ -153,7 +153,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeVectorInteger) { auto type = db.get_attribute_type("Collection", "value_int"); EXPECT_EQ(type.structure, psr::AttributeStructure::Vector); - EXPECT_EQ(type.data_type, psr::AttributeDataType::Integer); + EXPECT_EQ(type.data_type, psr::DataType::Integer); } TEST_F(SchemaValidatorFixture, GetAttributeTypeSetText) { @@ -162,7 +162,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeSetText) { auto type = db.get_attribute_type("Collection", "tag"); EXPECT_EQ(type.structure, psr::AttributeStructure::Set); - EXPECT_EQ(type.data_type, psr::AttributeDataType::Text); + EXPECT_EQ(type.data_type, psr::DataType::Text); } // ============================================================================ @@ -175,7 +175,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeVectorReal) { auto type = db.get_attribute_type("Collection", "value_float"); EXPECT_EQ(type.structure, psr::AttributeStructure::Vector); - EXPECT_EQ(type.data_type, psr::AttributeDataType::Real); + EXPECT_EQ(type.data_type, psr::DataType::Real); } TEST_F(SchemaValidatorFixture, GetAttributeTypeForeignKeyAsInteger) { @@ -185,7 +185,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeForeignKeyAsInteger) { auto type = db.get_attribute_type("Child", "parent_id"); EXPECT_EQ(type.structure, psr::AttributeStructure::Scalar); - EXPECT_EQ(type.data_type, psr::AttributeDataType::Integer); + EXPECT_EQ(type.data_type, psr::DataType::Integer); } TEST_F(SchemaValidatorFixture, GetAttributeTypeSelfReference) { @@ -195,7 +195,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeSelfReference) { auto type = db.get_attribute_type("Child", "sibling_id"); EXPECT_EQ(type.structure, psr::AttributeStructure::Scalar); - EXPECT_EQ(type.data_type, psr::AttributeDataType::Integer); + EXPECT_EQ(type.data_type, psr::DataType::Integer); } // ============================================================================ @@ -226,7 +226,7 @@ TEST_F(SchemaValidatorFixture, RelationsSchemaWithVectorFK) { // Verify the schema loaded successfully with vector FK table auto type = db.get_attribute_type("Child", "label"); - EXPECT_EQ(type.data_type, psr::AttributeDataType::Text); + EXPECT_EQ(type.data_type, psr::DataType::Text); } // ============================================================================ @@ -295,5 +295,5 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeIdColumn) { // 'id' column should exist and be INTEGER auto type = db.get_attribute_type("Configuration", "id"); EXPECT_EQ(type.structure, psr::AttributeStructure::Scalar); - EXPECT_EQ(type.data_type, psr::AttributeDataType::Integer); + EXPECT_EQ(type.data_type, psr::DataType::Integer); } From 58ac4c591dd8844e8953e1a7de27d0b5cce8e749 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 15:49:20 -0300 Subject: [PATCH 06/12] update --- include/psr/attribute_type.h | 4 ++-- src/c_api_database.cpp | 6 +++--- src/database.cpp | 6 +++--- src/schema_validator.cpp | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/psr/attribute_type.h b/include/psr/attribute_type.h index 4dee4aa..104325a 100644 --- a/include/psr/attribute_type.h +++ b/include/psr/attribute_type.h @@ -6,10 +6,10 @@ namespace psr { -enum class AttributeStructure { Scalar, Vector, Set }; +enum class DataStructure { Scalar, Vector, Set }; struct PSR_API AttributeType { - AttributeStructure structure; + DataStructure structure; DataType data_type; }; diff --git a/src/c_api_database.cpp b/src/c_api_database.cpp index cf55927..7cb0b36 100644 --- a/src/c_api_database.cpp +++ b/src/c_api_database.cpp @@ -893,13 +893,13 @@ PSR_C_API psr_error_t psr_database_get_attribute_type(psr_database_t* db, auto attr_type = db->db.get_attribute_type(collection, attribute); switch (attr_type.structure) { - case psr::AttributeStructure::Scalar: + case psr::DataStructure::Scalar: *out_structure = PSR_ATTRIBUTE_SCALAR; break; - case psr::AttributeStructure::Vector: + case psr::DataStructure::Vector: *out_structure = PSR_ATTRIBUTE_VECTOR; break; - case psr::AttributeStructure::Set: + case psr::DataStructure::Set: *out_structure = PSR_ATTRIBUTE_SET; break; } diff --git a/src/database.cpp b/src/database.cpp index b7735b3..db7e1ca 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -1380,7 +1380,7 @@ AttributeType Database::get_attribute_type(const std::string& collection, const if (table_def->has_column(attribute)) { auto data_type = table_def->get_data_type(attribute); if (data_type) { - return AttributeType{AttributeStructure::Scalar, *data_type}; + return AttributeType{DataStructure::Scalar, *data_type}; } } @@ -1395,7 +1395,7 @@ AttributeType Database::get_attribute_type(const std::string& collection, const if (vec_table && vec_table->has_column(attribute)) { auto data_type = vec_table->get_data_type(attribute); if (data_type) { - return AttributeType{AttributeStructure::Vector, *data_type}; + return AttributeType{DataStructure::Vector, *data_type}; } } } @@ -1411,7 +1411,7 @@ AttributeType Database::get_attribute_type(const std::string& collection, const if (set_table && set_table->has_column(attribute)) { auto data_type = set_table->get_data_type(attribute); if (data_type) { - return AttributeType{AttributeStructure::Set, *data_type}; + return AttributeType{DataStructure::Set, *data_type}; } } } diff --git a/src/schema_validator.cpp b/src/schema_validator.cpp index 60bca1e..91c0860 100644 --- a/src/schema_validator.cpp +++ b/src/schema_validator.cpp @@ -85,7 +85,7 @@ void SchemaValidator::validate_collection(const std::string& name) { } // Check for UNIQUE constraint on label - bool label_unique = false; + auto label_unique = false; for (const auto& idx : table->indexes) { if (idx.unique && idx.columns.size() == 1 && idx.columns[0] == "label") { label_unique = true; @@ -104,7 +104,7 @@ void SchemaValidator::validate_vector_table(const std::string& name) { } // Get parent collection - std::string parent = schema_.get_parent_collection(name); + auto parent = schema_.get_parent_collection(name); if (std::find(collections_.begin(), collections_.end(), parent) == collections_.end()) { validation_error("Vector table '" + name + "' references non-existent collection '" + parent + "'"); } From b58eaede581bce6e5aa544c699169aabf17cd2de Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 15:54:59 -0300 Subject: [PATCH 07/12] update --- tests/test_database_read.cpp | 12 ++++++------ tests/test_schema_validator.cpp | 18 +++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/test_database_read.cpp b/tests/test_database_read.cpp index e86f7bd..2c073f6 100644 --- a/tests/test_database_read.cpp +++ b/tests/test_database_read.cpp @@ -478,7 +478,7 @@ TEST(Database, GetAttributeTypeScalarInteger) { auto db = psr::Database::from_schema(":memory:", VALID_SCHEMA("basic.sql"), {.console_level = psr::LogLevel::off}); auto attr_type = db.get_attribute_type("Configuration", "integer_attribute"); - EXPECT_EQ(attr_type.structure, psr::AttributeStructure::Scalar); + EXPECT_EQ(attr_type.structure, psr::DataStructure::Scalar); EXPECT_EQ(attr_type.data_type, psr::DataType::Integer); } @@ -486,7 +486,7 @@ TEST(Database, GetAttributeTypeScalarReal) { auto db = psr::Database::from_schema(":memory:", VALID_SCHEMA("basic.sql"), {.console_level = psr::LogLevel::off}); auto attr_type = db.get_attribute_type("Configuration", "float_attribute"); - EXPECT_EQ(attr_type.structure, psr::AttributeStructure::Scalar); + EXPECT_EQ(attr_type.structure, psr::DataStructure::Scalar); EXPECT_EQ(attr_type.data_type, psr::DataType::Real); } @@ -494,7 +494,7 @@ TEST(Database, GetAttributeTypeScalarText) { auto db = psr::Database::from_schema(":memory:", VALID_SCHEMA("basic.sql"), {.console_level = psr::LogLevel::off}); auto attr_type = db.get_attribute_type("Configuration", "string_attribute"); - EXPECT_EQ(attr_type.structure, psr::AttributeStructure::Scalar); + EXPECT_EQ(attr_type.structure, psr::DataStructure::Scalar); EXPECT_EQ(attr_type.data_type, psr::DataType::Text); } @@ -503,7 +503,7 @@ TEST(Database, GetAttributeTypeVectorInteger) { psr::Database::from_schema(":memory:", VALID_SCHEMA("collections.sql"), {.console_level = psr::LogLevel::off}); auto attr_type = db.get_attribute_type("Collection", "value_int"); - EXPECT_EQ(attr_type.structure, psr::AttributeStructure::Vector); + EXPECT_EQ(attr_type.structure, psr::DataStructure::Vector); EXPECT_EQ(attr_type.data_type, psr::DataType::Integer); } @@ -512,7 +512,7 @@ TEST(Database, GetAttributeTypeVectorReal) { psr::Database::from_schema(":memory:", VALID_SCHEMA("collections.sql"), {.console_level = psr::LogLevel::off}); auto attr_type = db.get_attribute_type("Collection", "value_float"); - EXPECT_EQ(attr_type.structure, psr::AttributeStructure::Vector); + EXPECT_EQ(attr_type.structure, psr::DataStructure::Vector); EXPECT_EQ(attr_type.data_type, psr::DataType::Real); } @@ -521,7 +521,7 @@ TEST(Database, GetAttributeTypeSetText) { psr::Database::from_schema(":memory:", VALID_SCHEMA("collections.sql"), {.console_level = psr::LogLevel::off}); auto attr_type = db.get_attribute_type("Collection", "tag"); - EXPECT_EQ(attr_type.structure, psr::AttributeStructure::Set); + EXPECT_EQ(attr_type.structure, psr::DataStructure::Set); EXPECT_EQ(attr_type.data_type, psr::DataType::Text); } diff --git a/tests/test_schema_validator.cpp b/tests/test_schema_validator.cpp index ed31aaf..146b07f 100644 --- a/tests/test_schema_validator.cpp +++ b/tests/test_schema_validator.cpp @@ -125,7 +125,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeScalarInteger) { auto type = db.get_attribute_type("Configuration", "integer_attribute"); - EXPECT_EQ(type.structure, psr::AttributeStructure::Scalar); + EXPECT_EQ(type.structure, psr::DataStructure::Scalar); EXPECT_EQ(type.data_type, psr::DataType::Integer); } @@ -134,7 +134,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeScalarReal) { auto type = db.get_attribute_type("Configuration", "float_attribute"); - EXPECT_EQ(type.structure, psr::AttributeStructure::Scalar); + EXPECT_EQ(type.structure, psr::DataStructure::Scalar); EXPECT_EQ(type.data_type, psr::DataType::Real); } @@ -143,7 +143,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeScalarText) { auto type = db.get_attribute_type("Configuration", "label"); - EXPECT_EQ(type.structure, psr::AttributeStructure::Scalar); + EXPECT_EQ(type.structure, psr::DataStructure::Scalar); EXPECT_EQ(type.data_type, psr::DataType::Text); } @@ -152,7 +152,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeVectorInteger) { auto type = db.get_attribute_type("Collection", "value_int"); - EXPECT_EQ(type.structure, psr::AttributeStructure::Vector); + EXPECT_EQ(type.structure, psr::DataStructure::Vector); EXPECT_EQ(type.data_type, psr::DataType::Integer); } @@ -161,7 +161,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeSetText) { auto type = db.get_attribute_type("Collection", "tag"); - EXPECT_EQ(type.structure, psr::AttributeStructure::Set); + EXPECT_EQ(type.structure, psr::DataStructure::Set); EXPECT_EQ(type.data_type, psr::DataType::Text); } @@ -174,7 +174,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeVectorReal) { auto type = db.get_attribute_type("Collection", "value_float"); - EXPECT_EQ(type.structure, psr::AttributeStructure::Vector); + EXPECT_EQ(type.structure, psr::DataStructure::Vector); EXPECT_EQ(type.data_type, psr::DataType::Real); } @@ -184,7 +184,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeForeignKeyAsInteger) { // parent_id is a foreign key but stored as INTEGER auto type = db.get_attribute_type("Child", "parent_id"); - EXPECT_EQ(type.structure, psr::AttributeStructure::Scalar); + EXPECT_EQ(type.structure, psr::DataStructure::Scalar); EXPECT_EQ(type.data_type, psr::DataType::Integer); } @@ -194,7 +194,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeSelfReference) { // sibling_id is a self-referencing foreign key auto type = db.get_attribute_type("Child", "sibling_id"); - EXPECT_EQ(type.structure, psr::AttributeStructure::Scalar); + EXPECT_EQ(type.structure, psr::DataStructure::Scalar); EXPECT_EQ(type.data_type, psr::DataType::Integer); } @@ -294,6 +294,6 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeIdColumn) { // 'id' column should exist and be INTEGER auto type = db.get_attribute_type("Configuration", "id"); - EXPECT_EQ(type.structure, psr::AttributeStructure::Scalar); + EXPECT_EQ(type.structure, psr::DataStructure::Scalar); EXPECT_EQ(type.data_type, psr::DataType::Integer); } From 3272722ddb6a01ad52b1db2100ef665646174240 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 16:05:23 -0300 Subject: [PATCH 08/12] update --- bindings/dart/lib/src/database.dart | 10 ++--- bindings/dart/lib/src/ffi/bindings.dart | 8 ++-- bindings/dart/test/read_test.dart | 12 +++--- bindings/julia/src/PSRDatabase.jl | 8 ++-- bindings/julia/src/c_api.jl | 10 ++--- bindings/julia/src/database.jl | 4 +- bindings/julia/test/test_read.jl | 12 +++--- include/psr/attribute_type.h | 2 +- include/psr/c/database.h | 6 +-- src/c_api_database.cpp | 10 ++--- tests/test_c_api_database_read.cpp | 50 ++++++++++++------------- tests/test_database_read.cpp | 12 +++--- tests/test_schema_validator.cpp | 18 ++++----- 13 files changed, 81 insertions(+), 81 deletions(-) diff --git a/bindings/dart/lib/src/database.dart b/bindings/dart/lib/src/database.dart index 56d64c1..b47f9cd 100644 --- a/bindings/dart/lib/src/database.dart +++ b/bindings/dart/lib/src/database.dart @@ -868,19 +868,19 @@ class Database { } /// Returns the structure and data type of an attribute. - ({String structure, String dataType}) getAttributeType(String collection, String attribute) { + ({String dataStructure, String dataType}) getAttributeType(String collection, String attribute) { _ensureNotClosed(); final arena = Arena(); try { - final outStructure = arena(); + final outDataStructure = arena(); final outDataType = arena(); final err = bindings.psr_database_get_attribute_type( _ptr, collection.toNativeUtf8(allocator: arena).cast(), attribute.toNativeUtf8(allocator: arena).cast(), - outStructure, + outDataStructure, outDataType, ); @@ -888,7 +888,7 @@ class Database { throw DatabaseException.fromError(err, "Failed to get attribute type for '$collection.$attribute'"); } - final structure = switch (outStructure.value) { + final dataStructure = switch (outDataStructure.value) { 0 => 'scalar', 1 => 'vector', 2 => 'set', @@ -902,7 +902,7 @@ class Database { _ => 'unknown', }; - return (structure: structure, dataType: dataType); + return (dataStructure: dataStructure, dataType: dataType); } finally { arena.releaseAll(); } diff --git a/bindings/dart/lib/src/ffi/bindings.dart b/bindings/dart/lib/src/ffi/bindings.dart index 75d81b0..9e1fd65 100644 --- a/bindings/dart/lib/src/ffi/bindings.dart +++ b/bindings/dart/lib/src/ffi/bindings.dart @@ -1486,10 +1486,10 @@ abstract class psr_log_level_t { static const int PSR_LOG_OFF = 4; } -abstract class psr_attribute_structure_t { - static const int PSR_ATTRIBUTE_SCALAR = 0; - static const int PSR_ATTRIBUTE_VECTOR = 1; - static const int PSR_ATTRIBUTE_SET = 2; +abstract class psr_data_structure_t { + static const int PSR_DATA_STRUCTURE_SCALAR = 0; + static const int PSR_DATA_STRUCTURE_VECTOR = 1; + static const int PSR_DATA_STRUCTURE_SET = 2; } abstract class psr_data_type_t { diff --git a/bindings/dart/test/read_test.dart b/bindings/dart/test/read_test.dart index c00317c..8ce6d93 100644 --- a/bindings/dart/test/read_test.dart +++ b/bindings/dart/test/read_test.dart @@ -622,7 +622,7 @@ void main() { ); try { final result = db.getAttributeType('Configuration', 'integer_attribute'); - expect(result.structure, equals('scalar')); + expect(result.dataStructure, equals('scalar')); expect(result.dataType, equals('integer')); } finally { db.close(); @@ -636,7 +636,7 @@ void main() { ); try { final result = db.getAttributeType('Configuration', 'float_attribute'); - expect(result.structure, equals('scalar')); + expect(result.dataStructure, equals('scalar')); expect(result.dataType, equals('real')); } finally { db.close(); @@ -650,7 +650,7 @@ void main() { ); try { final result = db.getAttributeType('Configuration', 'string_attribute'); - expect(result.structure, equals('scalar')); + expect(result.dataStructure, equals('scalar')); expect(result.dataType, equals('text')); } finally { db.close(); @@ -664,7 +664,7 @@ void main() { ); try { final result = db.getAttributeType('Collection', 'value_int'); - expect(result.structure, equals('vector')); + expect(result.dataStructure, equals('vector')); expect(result.dataType, equals('integer')); } finally { db.close(); @@ -678,7 +678,7 @@ void main() { ); try { final result = db.getAttributeType('Collection', 'value_float'); - expect(result.structure, equals('vector')); + expect(result.dataStructure, equals('vector')); expect(result.dataType, equals('real')); } finally { db.close(); @@ -692,7 +692,7 @@ void main() { ); try { final result = db.getAttributeType('Collection', 'tag'); - expect(result.structure, equals('set')); + expect(result.dataStructure, equals('set')); expect(result.dataType, equals('text')); } finally { db.close(); diff --git a/bindings/julia/src/PSRDatabase.jl b/bindings/julia/src/PSRDatabase.jl index 51d406d..e468d24 100644 --- a/bindings/julia/src/PSRDatabase.jl +++ b/bindings/julia/src/PSRDatabase.jl @@ -10,13 +10,13 @@ include("lua_runner.jl") export Element, Database, LuaRunner, DatabaseException export get_attribute_type -export PSR_ATTRIBUTE_SCALAR, PSR_ATTRIBUTE_VECTOR, PSR_ATTRIBUTE_SET +export PSR_DATA_STRUCTURE_SCALAR, PSR_DATA_STRUCTURE_VECTOR, PSR_DATA_STRUCTURE_SET export PSR_DATA_TYPE_INTEGER, PSR_DATA_TYPE_REAL, PSR_DATA_TYPE_TEXT # Re-export enums from C module -const PSR_ATTRIBUTE_SCALAR = C.PSR_ATTRIBUTE_SCALAR -const PSR_ATTRIBUTE_VECTOR = C.PSR_ATTRIBUTE_VECTOR -const PSR_ATTRIBUTE_SET = C.PSR_ATTRIBUTE_SET +const PSR_DATA_STRUCTURE_SCALAR = C.PSR_DATA_STRUCTURE_SCALAR +const PSR_DATA_STRUCTURE_VECTOR = C.PSR_DATA_STRUCTURE_VECTOR +const PSR_DATA_STRUCTURE_SET = C.PSR_DATA_STRUCTURE_SET const PSR_DATA_TYPE_INTEGER = C.PSR_DATA_TYPE_INTEGER const PSR_DATA_TYPE_REAL = C.PSR_DATA_TYPE_REAL const PSR_DATA_TYPE_TEXT = C.PSR_DATA_TYPE_TEXT diff --git a/bindings/julia/src/c_api.jl b/bindings/julia/src/c_api.jl index ffd7582..020c93f 100644 --- a/bindings/julia/src/c_api.jl +++ b/bindings/julia/src/c_api.jl @@ -37,10 +37,10 @@ const libpsr_database_c = joinpath(@__DIR__, "..", "..", "..", "build", library_ PSR_ERROR_NOT_FOUND = -6 end -@cenum psr_attribute_structure_t::Int32 begin - PSR_ATTRIBUTE_SCALAR = 0 - PSR_ATTRIBUTE_VECTOR = 1 - PSR_ATTRIBUTE_SET = 2 +@cenum psr_data_structure_t::Int32 begin + PSR_DATA_STRUCTURE_SCALAR = 0 + PSR_DATA_STRUCTURE_VECTOR = 1 + PSR_DATA_STRUCTURE_SET = 2 end @cenum psr_data_type_t::Int32 begin @@ -199,7 +199,7 @@ function psr_database_read_element_ids(db, collection, out_ids, out_count) end function psr_database_get_attribute_type(db, collection, attribute, out_structure, out_data_type) - @ccall libpsr_database_c.psr_database_get_attribute_type(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, out_structure::Ptr{psr_attribute_structure_t}, out_data_type::Ptr{psr_data_type_t})::psr_error_t + @ccall libpsr_database_c.psr_database_get_attribute_type(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, out_structure::Ptr{psr_data_structure_t}, out_data_type::Ptr{psr_data_type_t})::psr_error_t end function psr_database_update_scalar_integer(db, collection, attribute, id, value) diff --git a/bindings/julia/src/database.jl b/bindings/julia/src/database.jl index 0d0594b..af84e32 100644 --- a/bindings/julia/src/database.jl +++ b/bindings/julia/src/database.jl @@ -510,7 +510,7 @@ function read_element_ids(db::Database, collection::String) end function get_attribute_type(db::Database, collection::String, attribute::String) - out_structure = Ref{C.psr_attribute_structure_t}(C.PSR_ATTRIBUTE_SCALAR) + out_structure = Ref{C.psr_data_structure_t}(C.PSR_DATA_STRUCTURE_SCALAR) out_data_type = Ref{C.psr_data_type_t}(C.PSR_DATA_TYPE_INTEGER) err = C.psr_database_get_attribute_type(db.ptr, collection, attribute, out_structure, out_data_type) @@ -518,7 +518,7 @@ function get_attribute_type(db::Database, collection::String, attribute::String) throw(DatabaseException("Failed to get attribute type for '$collection.$attribute'")) end - return (structure = out_structure[], data_type = out_data_type[]) + return (data_structure = out_structure[], data_type = out_data_type[]) end function delete_element_by_id!(db::Database, collection::String, id::Int64) diff --git a/bindings/julia/test/test_read.jl b/bindings/julia/test/test_read.jl index fe92174..a437fcb 100644 --- a/bindings/julia/test/test_read.jl +++ b/bindings/julia/test/test_read.jl @@ -361,7 +361,7 @@ end db = PSRDatabase.from_schema(":memory:", path_schema) result = PSRDatabase.get_attribute_type(db, "Configuration", "integer_attribute") - @test result.structure == PSRDatabase.PSR_ATTRIBUTE_SCALAR + @test result.data_structure == PSRDatabase.PSR_DATA_STRUCTURE_SCALAR @test result.data_type == PSRDatabase.PSR_DATA_TYPE_INTEGER PSRDatabase.close!(db) @@ -372,7 +372,7 @@ end db = PSRDatabase.from_schema(":memory:", path_schema) result = PSRDatabase.get_attribute_type(db, "Configuration", "float_attribute") - @test result.structure == PSRDatabase.PSR_ATTRIBUTE_SCALAR + @test result.data_structure == PSRDatabase.PSR_DATA_STRUCTURE_SCALAR @test result.data_type == PSRDatabase.PSR_DATA_TYPE_REAL PSRDatabase.close!(db) @@ -383,7 +383,7 @@ end db = PSRDatabase.from_schema(":memory:", path_schema) result = PSRDatabase.get_attribute_type(db, "Configuration", "string_attribute") - @test result.structure == PSRDatabase.PSR_ATTRIBUTE_SCALAR + @test result.data_structure == PSRDatabase.PSR_DATA_STRUCTURE_SCALAR @test result.data_type == PSRDatabase.PSR_DATA_TYPE_TEXT PSRDatabase.close!(db) @@ -394,7 +394,7 @@ end db = PSRDatabase.from_schema(":memory:", path_schema) result = PSRDatabase.get_attribute_type(db, "Collection", "value_int") - @test result.structure == PSRDatabase.PSR_ATTRIBUTE_VECTOR + @test result.data_structure == PSRDatabase.PSR_DATA_STRUCTURE_VECTOR @test result.data_type == PSRDatabase.PSR_DATA_TYPE_INTEGER PSRDatabase.close!(db) @@ -405,7 +405,7 @@ end db = PSRDatabase.from_schema(":memory:", path_schema) result = PSRDatabase.get_attribute_type(db, "Collection", "value_float") - @test result.structure == PSRDatabase.PSR_ATTRIBUTE_VECTOR + @test result.data_structure == PSRDatabase.PSR_DATA_STRUCTURE_VECTOR @test result.data_type == PSRDatabase.PSR_DATA_TYPE_REAL PSRDatabase.close!(db) @@ -416,7 +416,7 @@ end db = PSRDatabase.from_schema(":memory:", path_schema) result = PSRDatabase.get_attribute_type(db, "Collection", "tag") - @test result.structure == PSRDatabase.PSR_ATTRIBUTE_SET + @test result.data_structure == PSRDatabase.PSR_DATA_STRUCTURE_SET @test result.data_type == PSRDatabase.PSR_DATA_TYPE_TEXT PSRDatabase.close!(db) diff --git a/include/psr/attribute_type.h b/include/psr/attribute_type.h index 104325a..f9486c1 100644 --- a/include/psr/attribute_type.h +++ b/include/psr/attribute_type.h @@ -9,7 +9,7 @@ namespace psr { enum class DataStructure { Scalar, Vector, Set }; struct PSR_API AttributeType { - DataStructure structure; + DataStructure data_structure; DataType data_type; }; diff --git a/include/psr/c/database.h b/include/psr/c/database.h index b5b8848..e99c1ef 100644 --- a/include/psr/c/database.h +++ b/include/psr/c/database.h @@ -22,8 +22,8 @@ typedef struct { psr_log_level_t console_level; } psr_database_options_t; -// Attribute structure types -typedef enum { PSR_ATTRIBUTE_SCALAR = 0, PSR_ATTRIBUTE_VECTOR = 1, PSR_ATTRIBUTE_SET = 2 } psr_attribute_structure_t; +// Attribute data structure types +typedef enum { PSR_DATA_STRUCTURE_SCALAR = 0, PSR_DATA_STRUCTURE_VECTOR = 1, PSR_DATA_STRUCTURE_SET = 2 } psr_data_structure_t; // Attribute data types typedef enum { PSR_DATA_TYPE_INTEGER = 0, PSR_DATA_TYPE_REAL = 1, PSR_DATA_TYPE_TEXT = 2 } psr_data_type_t; @@ -208,7 +208,7 @@ PSR_C_API psr_error_t psr_database_read_element_ids(psr_database_t* db, PSR_C_API psr_error_t psr_database_get_attribute_type(psr_database_t* db, const char* collection, const char* attribute, - psr_attribute_structure_t* out_structure, + psr_data_structure_t* out_structure, psr_data_type_t* out_data_type); // Update scalar attributes (by element ID) diff --git a/src/c_api_database.cpp b/src/c_api_database.cpp index 7cb0b36..514bf67 100644 --- a/src/c_api_database.cpp +++ b/src/c_api_database.cpp @@ -884,7 +884,7 @@ PSR_C_API psr_error_t psr_database_update_set_strings(psr_database_t* db, PSR_C_API psr_error_t psr_database_get_attribute_type(psr_database_t* db, const char* collection, const char* attribute, - psr_attribute_structure_t* out_structure, + psr_data_structure_t* out_structure, psr_data_type_t* out_data_type) { if (!db || !collection || !attribute || !out_structure || !out_data_type) { return PSR_ERROR_INVALID_ARGUMENT; @@ -892,15 +892,15 @@ PSR_C_API psr_error_t psr_database_get_attribute_type(psr_database_t* db, try { auto attr_type = db->db.get_attribute_type(collection, attribute); - switch (attr_type.structure) { + switch (attr_type.data_structure) { case psr::DataStructure::Scalar: - *out_structure = PSR_ATTRIBUTE_SCALAR; + *out_structure = PSR_DATA_STRUCTURE_SCALAR; break; case psr::DataStructure::Vector: - *out_structure = PSR_ATTRIBUTE_VECTOR; + *out_structure = PSR_DATA_STRUCTURE_VECTOR; break; case psr::DataStructure::Set: - *out_structure = PSR_ATTRIBUTE_SET; + *out_structure = PSR_DATA_STRUCTURE_SET; break; } diff --git a/tests/test_c_api_database_read.cpp b/tests/test_c_api_database_read.cpp index 30aabed..d68915a 100644 --- a/tests/test_c_api_database_read.cpp +++ b/tests/test_c_api_database_read.cpp @@ -809,12 +809,12 @@ TEST(DatabaseCApi, GetAttributeTypeScalarInteger) { auto db = psr_database_from_schema(":memory:", VALID_SCHEMA("basic.sql").c_str(), &options); ASSERT_NE(db, nullptr); - psr_attribute_structure_t structure; + psr_data_structure_t data_structure; psr_data_type_t data_type; - auto err = psr_database_get_attribute_type(db, "Configuration", "integer_attribute", &structure, &data_type); + auto err = psr_database_get_attribute_type(db, "Configuration", "integer_attribute", &data_structure, &data_type); EXPECT_EQ(err, PSR_OK); - EXPECT_EQ(structure, PSR_ATTRIBUTE_SCALAR); + EXPECT_EQ(data_structure, PSR_DATA_STRUCTURE_SCALAR); EXPECT_EQ(data_type, PSR_DATA_TYPE_INTEGER); psr_database_close(db); @@ -826,12 +826,12 @@ TEST(DatabaseCApi, GetAttributeTypeScalarReal) { auto db = psr_database_from_schema(":memory:", VALID_SCHEMA("basic.sql").c_str(), &options); ASSERT_NE(db, nullptr); - psr_attribute_structure_t structure; + psr_data_structure_t data_structure; psr_data_type_t data_type; - auto err = psr_database_get_attribute_type(db, "Configuration", "float_attribute", &structure, &data_type); + auto err = psr_database_get_attribute_type(db, "Configuration", "float_attribute", &data_structure, &data_type); EXPECT_EQ(err, PSR_OK); - EXPECT_EQ(structure, PSR_ATTRIBUTE_SCALAR); + EXPECT_EQ(data_structure, PSR_DATA_STRUCTURE_SCALAR); EXPECT_EQ(data_type, PSR_DATA_TYPE_REAL); psr_database_close(db); @@ -843,12 +843,12 @@ TEST(DatabaseCApi, GetAttributeTypeScalarText) { auto db = psr_database_from_schema(":memory:", VALID_SCHEMA("basic.sql").c_str(), &options); ASSERT_NE(db, nullptr); - psr_attribute_structure_t structure; + psr_data_structure_t data_structure; psr_data_type_t data_type; - auto err = psr_database_get_attribute_type(db, "Configuration", "string_attribute", &structure, &data_type); + auto err = psr_database_get_attribute_type(db, "Configuration", "string_attribute", &data_structure, &data_type); EXPECT_EQ(err, PSR_OK); - EXPECT_EQ(structure, PSR_ATTRIBUTE_SCALAR); + EXPECT_EQ(data_structure, PSR_DATA_STRUCTURE_SCALAR); EXPECT_EQ(data_type, PSR_DATA_TYPE_TEXT); psr_database_close(db); @@ -860,12 +860,12 @@ TEST(DatabaseCApi, GetAttributeTypeVectorInteger) { auto db = psr_database_from_schema(":memory:", VALID_SCHEMA("collections.sql").c_str(), &options); ASSERT_NE(db, nullptr); - psr_attribute_structure_t structure; + psr_data_structure_t data_structure; psr_data_type_t data_type; - auto err = psr_database_get_attribute_type(db, "Collection", "value_int", &structure, &data_type); + auto err = psr_database_get_attribute_type(db, "Collection", "value_int", &data_structure, &data_type); EXPECT_EQ(err, PSR_OK); - EXPECT_EQ(structure, PSR_ATTRIBUTE_VECTOR); + EXPECT_EQ(data_structure, PSR_DATA_STRUCTURE_VECTOR); EXPECT_EQ(data_type, PSR_DATA_TYPE_INTEGER); psr_database_close(db); @@ -877,12 +877,12 @@ TEST(DatabaseCApi, GetAttributeTypeVectorReal) { auto db = psr_database_from_schema(":memory:", VALID_SCHEMA("collections.sql").c_str(), &options); ASSERT_NE(db, nullptr); - psr_attribute_structure_t structure; + psr_data_structure_t data_structure; psr_data_type_t data_type; - auto err = psr_database_get_attribute_type(db, "Collection", "value_float", &structure, &data_type); + auto err = psr_database_get_attribute_type(db, "Collection", "value_float", &data_structure, &data_type); EXPECT_EQ(err, PSR_OK); - EXPECT_EQ(structure, PSR_ATTRIBUTE_VECTOR); + EXPECT_EQ(data_structure, PSR_DATA_STRUCTURE_VECTOR); EXPECT_EQ(data_type, PSR_DATA_TYPE_REAL); psr_database_close(db); @@ -894,12 +894,12 @@ TEST(DatabaseCApi, GetAttributeTypeSetText) { auto db = psr_database_from_schema(":memory:", VALID_SCHEMA("collections.sql").c_str(), &options); ASSERT_NE(db, nullptr); - psr_attribute_structure_t structure; + psr_data_structure_t data_structure; psr_data_type_t data_type; - auto err = psr_database_get_attribute_type(db, "Collection", "tag", &structure, &data_type); + auto err = psr_database_get_attribute_type(db, "Collection", "tag", &data_structure, &data_type); EXPECT_EQ(err, PSR_OK); - EXPECT_EQ(structure, PSR_ATTRIBUTE_SET); + EXPECT_EQ(data_structure, PSR_DATA_STRUCTURE_SET); EXPECT_EQ(data_type, PSR_DATA_TYPE_TEXT); psr_database_close(db); @@ -911,9 +911,9 @@ TEST(DatabaseCApi, GetAttributeTypeNotFound) { auto db = psr_database_from_schema(":memory:", VALID_SCHEMA("basic.sql").c_str(), &options); ASSERT_NE(db, nullptr); - psr_attribute_structure_t structure; + psr_data_structure_t data_structure; psr_data_type_t data_type; - auto err = psr_database_get_attribute_type(db, "Configuration", "nonexistent", &structure, &data_type); + auto err = psr_database_get_attribute_type(db, "Configuration", "nonexistent", &data_structure, &data_type); EXPECT_EQ(err, PSR_ERROR_DATABASE); @@ -926,19 +926,19 @@ TEST(DatabaseCApi, GetAttributeTypeInvalidArgument) { auto db = psr_database_from_schema(":memory:", VALID_SCHEMA("basic.sql").c_str(), &options); ASSERT_NE(db, nullptr); - psr_attribute_structure_t structure; + psr_data_structure_t data_structure; psr_data_type_t data_type; // Null db - auto err = psr_database_get_attribute_type(nullptr, "Configuration", "label", &structure, &data_type); + auto err = psr_database_get_attribute_type(nullptr, "Configuration", "label", &data_structure, &data_type); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); // Null collection - err = psr_database_get_attribute_type(db, nullptr, "label", &structure, &data_type); + err = psr_database_get_attribute_type(db, nullptr, "label", &data_structure, &data_type); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); // Null attribute - err = psr_database_get_attribute_type(db, "Configuration", nullptr, &structure, &data_type); + err = psr_database_get_attribute_type(db, "Configuration", nullptr, &data_structure, &data_type); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); // Null out_structure @@ -946,7 +946,7 @@ TEST(DatabaseCApi, GetAttributeTypeInvalidArgument) { EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); // Null out_data_type - err = psr_database_get_attribute_type(db, "Configuration", "label", &structure, nullptr); + err = psr_database_get_attribute_type(db, "Configuration", "label", &data_structure, nullptr); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); psr_database_close(db); diff --git a/tests/test_database_read.cpp b/tests/test_database_read.cpp index 2c073f6..d84b4e1 100644 --- a/tests/test_database_read.cpp +++ b/tests/test_database_read.cpp @@ -478,7 +478,7 @@ TEST(Database, GetAttributeTypeScalarInteger) { auto db = psr::Database::from_schema(":memory:", VALID_SCHEMA("basic.sql"), {.console_level = psr::LogLevel::off}); auto attr_type = db.get_attribute_type("Configuration", "integer_attribute"); - EXPECT_EQ(attr_type.structure, psr::DataStructure::Scalar); + EXPECT_EQ(attr_type.data_structure, psr::DataStructure::Scalar); EXPECT_EQ(attr_type.data_type, psr::DataType::Integer); } @@ -486,7 +486,7 @@ TEST(Database, GetAttributeTypeScalarReal) { auto db = psr::Database::from_schema(":memory:", VALID_SCHEMA("basic.sql"), {.console_level = psr::LogLevel::off}); auto attr_type = db.get_attribute_type("Configuration", "float_attribute"); - EXPECT_EQ(attr_type.structure, psr::DataStructure::Scalar); + EXPECT_EQ(attr_type.data_structure, psr::DataStructure::Scalar); EXPECT_EQ(attr_type.data_type, psr::DataType::Real); } @@ -494,7 +494,7 @@ TEST(Database, GetAttributeTypeScalarText) { auto db = psr::Database::from_schema(":memory:", VALID_SCHEMA("basic.sql"), {.console_level = psr::LogLevel::off}); auto attr_type = db.get_attribute_type("Configuration", "string_attribute"); - EXPECT_EQ(attr_type.structure, psr::DataStructure::Scalar); + EXPECT_EQ(attr_type.data_structure, psr::DataStructure::Scalar); EXPECT_EQ(attr_type.data_type, psr::DataType::Text); } @@ -503,7 +503,7 @@ TEST(Database, GetAttributeTypeVectorInteger) { psr::Database::from_schema(":memory:", VALID_SCHEMA("collections.sql"), {.console_level = psr::LogLevel::off}); auto attr_type = db.get_attribute_type("Collection", "value_int"); - EXPECT_EQ(attr_type.structure, psr::DataStructure::Vector); + EXPECT_EQ(attr_type.data_structure, psr::DataStructure::Vector); EXPECT_EQ(attr_type.data_type, psr::DataType::Integer); } @@ -512,7 +512,7 @@ TEST(Database, GetAttributeTypeVectorReal) { psr::Database::from_schema(":memory:", VALID_SCHEMA("collections.sql"), {.console_level = psr::LogLevel::off}); auto attr_type = db.get_attribute_type("Collection", "value_float"); - EXPECT_EQ(attr_type.structure, psr::DataStructure::Vector); + EXPECT_EQ(attr_type.data_structure, psr::DataStructure::Vector); EXPECT_EQ(attr_type.data_type, psr::DataType::Real); } @@ -521,7 +521,7 @@ TEST(Database, GetAttributeTypeSetText) { psr::Database::from_schema(":memory:", VALID_SCHEMA("collections.sql"), {.console_level = psr::LogLevel::off}); auto attr_type = db.get_attribute_type("Collection", "tag"); - EXPECT_EQ(attr_type.structure, psr::DataStructure::Set); + EXPECT_EQ(attr_type.data_structure, psr::DataStructure::Set); EXPECT_EQ(attr_type.data_type, psr::DataType::Text); } diff --git a/tests/test_schema_validator.cpp b/tests/test_schema_validator.cpp index 146b07f..5d02dcf 100644 --- a/tests/test_schema_validator.cpp +++ b/tests/test_schema_validator.cpp @@ -125,7 +125,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeScalarInteger) { auto type = db.get_attribute_type("Configuration", "integer_attribute"); - EXPECT_EQ(type.structure, psr::DataStructure::Scalar); + EXPECT_EQ(type.data_structure, psr::DataStructure::Scalar); EXPECT_EQ(type.data_type, psr::DataType::Integer); } @@ -134,7 +134,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeScalarReal) { auto type = db.get_attribute_type("Configuration", "float_attribute"); - EXPECT_EQ(type.structure, psr::DataStructure::Scalar); + EXPECT_EQ(type.data_structure, psr::DataStructure::Scalar); EXPECT_EQ(type.data_type, psr::DataType::Real); } @@ -143,7 +143,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeScalarText) { auto type = db.get_attribute_type("Configuration", "label"); - EXPECT_EQ(type.structure, psr::DataStructure::Scalar); + EXPECT_EQ(type.data_structure, psr::DataStructure::Scalar); EXPECT_EQ(type.data_type, psr::DataType::Text); } @@ -152,7 +152,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeVectorInteger) { auto type = db.get_attribute_type("Collection", "value_int"); - EXPECT_EQ(type.structure, psr::DataStructure::Vector); + EXPECT_EQ(type.data_structure, psr::DataStructure::Vector); EXPECT_EQ(type.data_type, psr::DataType::Integer); } @@ -161,7 +161,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeSetText) { auto type = db.get_attribute_type("Collection", "tag"); - EXPECT_EQ(type.structure, psr::DataStructure::Set); + EXPECT_EQ(type.data_structure, psr::DataStructure::Set); EXPECT_EQ(type.data_type, psr::DataType::Text); } @@ -174,7 +174,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeVectorReal) { auto type = db.get_attribute_type("Collection", "value_float"); - EXPECT_EQ(type.structure, psr::DataStructure::Vector); + EXPECT_EQ(type.data_structure, psr::DataStructure::Vector); EXPECT_EQ(type.data_type, psr::DataType::Real); } @@ -184,7 +184,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeForeignKeyAsInteger) { // parent_id is a foreign key but stored as INTEGER auto type = db.get_attribute_type("Child", "parent_id"); - EXPECT_EQ(type.structure, psr::DataStructure::Scalar); + EXPECT_EQ(type.data_structure, psr::DataStructure::Scalar); EXPECT_EQ(type.data_type, psr::DataType::Integer); } @@ -194,7 +194,7 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeSelfReference) { // sibling_id is a self-referencing foreign key auto type = db.get_attribute_type("Child", "sibling_id"); - EXPECT_EQ(type.structure, psr::DataStructure::Scalar); + EXPECT_EQ(type.data_structure, psr::DataStructure::Scalar); EXPECT_EQ(type.data_type, psr::DataType::Integer); } @@ -294,6 +294,6 @@ TEST_F(SchemaValidatorFixture, GetAttributeTypeIdColumn) { // 'id' column should exist and be INTEGER auto type = db.get_attribute_type("Configuration", "id"); - EXPECT_EQ(type.structure, psr::DataStructure::Scalar); + EXPECT_EQ(type.data_structure, psr::DataStructure::Scalar); EXPECT_EQ(type.data_type, psr::DataType::Integer); } From be4bd048d28217926f4c9c2cf367f0cf948079ca Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 16:07:41 -0300 Subject: [PATCH 09/12] update --- bindings/dart/lib/src/ffi/bindings.dart | 94 ++++++++++++------------- include/psr/c/database.h | 6 +- 2 files changed, 52 insertions(+), 48 deletions(-) diff --git a/bindings/dart/lib/src/ffi/bindings.dart b/bindings/dart/lib/src/ffi/bindings.dart index 9e1fd65..0fe3a8b 100644 --- a/bindings/dart/lib/src/ffi/bindings.dart +++ b/bindings/dart/lib/src/ffi/bindings.dart @@ -174,6 +174,45 @@ class PsrDatabaseBindings { late final _psr_database_create_element = _psr_database_create_elementPtr .asFunction, ffi.Pointer, ffi.Pointer)>(); + int psr_database_update_element( + ffi.Pointer db, + ffi.Pointer collection, + int id, + ffi.Pointer element, + ) { + return _psr_database_update_element( + db, + collection, + id, + element, + ); + } + + late final _psr_database_update_elementPtr = _lookup< + ffi.NativeFunction< + ffi.Int32 Function(ffi.Pointer, ffi.Pointer, ffi.Int64, + ffi.Pointer)>>('psr_database_update_element'); + late final _psr_database_update_element = _psr_database_update_elementPtr + .asFunction, ffi.Pointer, int, ffi.Pointer)>(); + + int psr_database_delete_element_by_id( + ffi.Pointer db, + ffi.Pointer collection, + int id, + ) { + return _psr_database_delete_element_by_id( + db, + collection, + id, + ); + } + + late final _psr_database_delete_element_by_idPtr = + _lookup, ffi.Pointer, ffi.Int64)>>( + 'psr_database_delete_element_by_id'); + late final _psr_database_delete_element_by_id = _psr_database_delete_element_by_idPtr + .asFunction, ffi.Pointer, int)>(); + int psr_database_set_scalar_relation( ffi.Pointer db, ffi.Pointer collection, @@ -1034,45 +1073,6 @@ class PsrDatabaseBindings { int Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, int, ffi.Pointer>, int)>(); - int psr_database_delete_element_by_id( - ffi.Pointer db, - ffi.Pointer collection, - int id, - ) { - return _psr_database_delete_element_by_id( - db, - collection, - id, - ); - } - - late final _psr_database_delete_element_by_idPtr = - _lookup, ffi.Pointer, ffi.Int64)>>( - 'psr_database_delete_element_by_id'); - late final _psr_database_delete_element_by_id = _psr_database_delete_element_by_idPtr - .asFunction, ffi.Pointer, int)>(); - - int psr_database_update_element( - ffi.Pointer db, - ffi.Pointer collection, - int id, - ffi.Pointer element, - ) { - return _psr_database_update_element( - db, - collection, - id, - element, - ); - } - - late final _psr_database_update_elementPtr = _lookup< - ffi.NativeFunction< - ffi.Int32 Function(ffi.Pointer, ffi.Pointer, ffi.Int64, - ffi.Pointer)>>('psr_database_update_element'); - late final _psr_database_update_element = _psr_database_update_elementPtr - .asFunction, ffi.Pointer, int, ffi.Pointer)>(); - void psr_free_int_array( ffi.Pointer values, ) { @@ -1486,6 +1486,14 @@ abstract class psr_log_level_t { static const int PSR_LOG_OFF = 4; } +final class psr_database_options_t extends ffi.Struct { + @ffi.Int() + external int read_only; + + @ffi.Int32() + external int console_level; +} + abstract class psr_data_structure_t { static const int PSR_DATA_STRUCTURE_SCALAR = 0; static const int PSR_DATA_STRUCTURE_VECTOR = 1; @@ -1498,14 +1506,6 @@ abstract class psr_data_type_t { static const int PSR_DATA_TYPE_TEXT = 2; } -final class psr_database_options_t extends ffi.Struct { - @ffi.Int() - external int read_only; - - @ffi.Int32() - external int console_level; -} - final class psr_database extends ffi.Opaque {} typedef psr_database_t = psr_database; diff --git a/include/psr/c/database.h b/include/psr/c/database.h index e99c1ef..14cdfcc 100644 --- a/include/psr/c/database.h +++ b/include/psr/c/database.h @@ -23,7 +23,11 @@ typedef struct { } psr_database_options_t; // Attribute data structure types -typedef enum { PSR_DATA_STRUCTURE_SCALAR = 0, PSR_DATA_STRUCTURE_VECTOR = 1, PSR_DATA_STRUCTURE_SET = 2 } psr_data_structure_t; +typedef enum { + PSR_DATA_STRUCTURE_SCALAR = 0, + PSR_DATA_STRUCTURE_VECTOR = 1, + PSR_DATA_STRUCTURE_SET = 2 +} psr_data_structure_t; // Attribute data types typedef enum { PSR_DATA_TYPE_INTEGER = 0, PSR_DATA_TYPE_REAL = 1, PSR_DATA_TYPE_TEXT = 2 } psr_data_type_t; From 16cd6b27f573d547f69a3c097a35d422e929a825 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 16:08:42 -0300 Subject: [PATCH 10/12] update --- bindings/dart/lib/src/ffi/bindings.dart | 4 ++-- bindings/julia/src/database.jl | 6 +++--- include/psr/c/database.h | 2 +- src/c_api_database.cpp | 10 +++++----- tests/test_c_api_database_read.cpp | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bindings/dart/lib/src/ffi/bindings.dart b/bindings/dart/lib/src/ffi/bindings.dart index 0fe3a8b..4dd3de3 100644 --- a/bindings/dart/lib/src/ffi/bindings.dart +++ b/bindings/dart/lib/src/ffi/bindings.dart @@ -827,14 +827,14 @@ class PsrDatabaseBindings { ffi.Pointer db, ffi.Pointer collection, ffi.Pointer attribute, - ffi.Pointer out_structure, + ffi.Pointer out_data_structure, ffi.Pointer out_data_type, ) { return _psr_database_get_attribute_type( db, collection, attribute, - out_structure, + out_data_structure, out_data_type, ); } diff --git a/bindings/julia/src/database.jl b/bindings/julia/src/database.jl index af84e32..08fea7a 100644 --- a/bindings/julia/src/database.jl +++ b/bindings/julia/src/database.jl @@ -510,15 +510,15 @@ function read_element_ids(db::Database, collection::String) end function get_attribute_type(db::Database, collection::String, attribute::String) - out_structure = Ref{C.psr_data_structure_t}(C.PSR_DATA_STRUCTURE_SCALAR) + out_data_structure = Ref{C.psr_data_structure_t}(C.PSR_DATA_STRUCTURE_SCALAR) out_data_type = Ref{C.psr_data_type_t}(C.PSR_DATA_TYPE_INTEGER) - err = C.psr_database_get_attribute_type(db.ptr, collection, attribute, out_structure, out_data_type) + err = C.psr_database_get_attribute_type(db.ptr, collection, attribute, out_data_structure, out_data_type) if err != C.PSR_OK throw(DatabaseException("Failed to get attribute type for '$collection.$attribute'")) end - return (data_structure = out_structure[], data_type = out_data_type[]) + return (data_structure = out_data_structure[], data_type = out_data_type[]) end function delete_element_by_id!(db::Database, collection::String, id::Int64) diff --git a/include/psr/c/database.h b/include/psr/c/database.h index 14cdfcc..e950983 100644 --- a/include/psr/c/database.h +++ b/include/psr/c/database.h @@ -212,7 +212,7 @@ PSR_C_API psr_error_t psr_database_read_element_ids(psr_database_t* db, PSR_C_API psr_error_t psr_database_get_attribute_type(psr_database_t* db, const char* collection, const char* attribute, - psr_data_structure_t* out_structure, + psr_data_structure_t* out_data_structure, psr_data_type_t* out_data_type); // Update scalar attributes (by element ID) diff --git a/src/c_api_database.cpp b/src/c_api_database.cpp index 514bf67..f16ec0f 100644 --- a/src/c_api_database.cpp +++ b/src/c_api_database.cpp @@ -884,9 +884,9 @@ PSR_C_API psr_error_t psr_database_update_set_strings(psr_database_t* db, PSR_C_API psr_error_t psr_database_get_attribute_type(psr_database_t* db, const char* collection, const char* attribute, - psr_data_structure_t* out_structure, + psr_data_structure_t* out_data_structure, psr_data_type_t* out_data_type) { - if (!db || !collection || !attribute || !out_structure || !out_data_type) { + if (!db || !collection || !attribute || !out_data_structure || !out_data_type) { return PSR_ERROR_INVALID_ARGUMENT; } try { @@ -894,13 +894,13 @@ PSR_C_API psr_error_t psr_database_get_attribute_type(psr_database_t* db, switch (attr_type.data_structure) { case psr::DataStructure::Scalar: - *out_structure = PSR_DATA_STRUCTURE_SCALAR; + *out_data_structure = PSR_DATA_STRUCTURE_SCALAR; break; case psr::DataStructure::Vector: - *out_structure = PSR_DATA_STRUCTURE_VECTOR; + *out_data_structure = PSR_DATA_STRUCTURE_VECTOR; break; case psr::DataStructure::Set: - *out_structure = PSR_DATA_STRUCTURE_SET; + *out_data_structure = PSR_DATA_STRUCTURE_SET; break; } diff --git a/tests/test_c_api_database_read.cpp b/tests/test_c_api_database_read.cpp index d68915a..ba0d7a2 100644 --- a/tests/test_c_api_database_read.cpp +++ b/tests/test_c_api_database_read.cpp @@ -941,7 +941,7 @@ TEST(DatabaseCApi, GetAttributeTypeInvalidArgument) { err = psr_database_get_attribute_type(db, "Configuration", nullptr, &data_structure, &data_type); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); - // Null out_structure + // Null out_data_structure err = psr_database_get_attribute_type(db, "Configuration", "label", nullptr, &data_type); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); From af1ca6207556036d4d18c07672fbcb1bbc0f6504 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 16:11:54 -0300 Subject: [PATCH 11/12] update --- include/psr/c/database.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/psr/c/database.h b/include/psr/c/database.h index e950983..c9a4ed8 100644 --- a/include/psr/c/database.h +++ b/include/psr/c/database.h @@ -22,7 +22,7 @@ typedef struct { psr_log_level_t console_level; } psr_database_options_t; -// Attribute data structure types +// Attribute data structure typedef enum { PSR_DATA_STRUCTURE_SCALAR = 0, PSR_DATA_STRUCTURE_VECTOR = 1, From 8b1ac1acb47d951b99eb52875cb45539e33353ad Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 16:12:15 -0300 Subject: [PATCH 12/12] update --- bindings/julia/src/c_api.jl | 44 ++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/bindings/julia/src/c_api.jl b/bindings/julia/src/c_api.jl index 020c93f..e403c7f 100644 --- a/bindings/julia/src/c_api.jl +++ b/bindings/julia/src/c_api.jl @@ -37,18 +37,6 @@ const libpsr_database_c = joinpath(@__DIR__, "..", "..", "..", "build", library_ PSR_ERROR_NOT_FOUND = -6 end -@cenum psr_data_structure_t::Int32 begin - PSR_DATA_STRUCTURE_SCALAR = 0 - PSR_DATA_STRUCTURE_VECTOR = 1 - PSR_DATA_STRUCTURE_SET = 2 -end - -@cenum psr_data_type_t::Int32 begin - PSR_DATA_TYPE_INTEGER = 0 - PSR_DATA_TYPE_REAL = 1 - PSR_DATA_TYPE_TEXT = 2 -end - function psr_error_string(error) @ccall libpsr_database_c.psr_error_string(error::psr_error_t)::Ptr{Cchar} end @@ -70,6 +58,18 @@ struct psr_database_options_t console_level::psr_log_level_t end +@cenum psr_data_structure_t::UInt32 begin + PSR_DATA_STRUCTURE_SCALAR = 0 + PSR_DATA_STRUCTURE_VECTOR = 1 + PSR_DATA_STRUCTURE_SET = 2 +end + +@cenum psr_data_type_t::UInt32 begin + PSR_DATA_TYPE_INTEGER = 0 + PSR_DATA_TYPE_REAL = 1 + PSR_DATA_TYPE_TEXT = 2 +end + function psr_database_options_default() @ccall libpsr_database_c.psr_database_options_default()::psr_database_options_t end @@ -114,6 +114,14 @@ function psr_database_create_element(db, collection, element) @ccall libpsr_database_c.psr_database_create_element(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, element::Ptr{psr_element_t})::Int64 end +function psr_database_update_element(db, collection, id, element) + @ccall libpsr_database_c.psr_database_update_element(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, id::Int64, element::Ptr{psr_element_t})::psr_error_t +end + +function psr_database_delete_element_by_id(db, collection, id) + @ccall libpsr_database_c.psr_database_delete_element_by_id(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, id::Int64)::psr_error_t +end + function psr_database_set_scalar_relation(db, collection, attribute, from_label, to_label) @ccall libpsr_database_c.psr_database_set_scalar_relation(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, from_label::Ptr{Cchar}, to_label::Ptr{Cchar})::psr_error_t end @@ -198,8 +206,8 @@ function psr_database_read_element_ids(db, collection, out_ids, out_count) @ccall libpsr_database_c.psr_database_read_element_ids(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, out_ids::Ptr{Ptr{Int64}}, out_count::Ptr{Csize_t})::psr_error_t end -function psr_database_get_attribute_type(db, collection, attribute, out_structure, out_data_type) - @ccall libpsr_database_c.psr_database_get_attribute_type(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, out_structure::Ptr{psr_data_structure_t}, out_data_type::Ptr{psr_data_type_t})::psr_error_t +function psr_database_get_attribute_type(db, collection, attribute, out_data_structure, out_data_type) + @ccall libpsr_database_c.psr_database_get_attribute_type(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, out_data_structure::Ptr{psr_data_structure_t}, out_data_type::Ptr{psr_data_type_t})::psr_error_t end function psr_database_update_scalar_integer(db, collection, attribute, id, value) @@ -238,14 +246,6 @@ function psr_database_update_set_strings(db, collection, attribute, id, values, @ccall libpsr_database_c.psr_database_update_set_strings(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, id::Int64, values::Ptr{Ptr{Cchar}}, count::Csize_t)::psr_error_t end -function psr_database_delete_element_by_id(db, collection, id) - @ccall libpsr_database_c.psr_database_delete_element_by_id(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, id::Int64)::psr_error_t -end - -function psr_database_update_element(db, collection, id, element) - @ccall libpsr_database_c.psr_database_update_element(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, id::Int64, element::Ptr{psr_element_t})::psr_error_t -end - function psr_free_int_array(values) @ccall libpsr_database_c.psr_free_int_array(values::Ptr{Int64})::Cvoid end