|
MantisBase v0.3.4
|
Represents a single field in a database table schema. More...
#include <entity_schema_field.h>
Public Member Functions | |
| EntitySchemaField (std::string field_name, std::string field_type) | |
| Construct field with name and type. | |
| EntitySchemaField (const nlohmann::json &field_schema) | |
| Construct field from JSON schema object. | |
| EntitySchemaField (const EntitySchemaField &other) | |
| bool | operator== (const EntitySchemaField &other) const |
| std::string | id () const |
| Get field unique identifier. | |
| std::string | name () const |
| Get field name. | |
| EntitySchemaField & | setName (const std::string &name) |
| Set field name (fluent interface). | |
| std::string | type () const |
| Get field type. | |
| EntitySchemaField & | setType (const std::string &type) |
| Set field type (fluent interface). | |
| bool | required () const |
| Check if field is required. | |
| EntitySchemaField & | setRequired (bool required) |
| Set required flag (fluent interface). | |
| bool | isPrimaryKey () const |
| Check if field is primary key. | |
| EntitySchemaField & | setIsPrimaryKey (bool pk) |
| Set primary key flag (fluent interface). | |
| bool | isSystem () const |
| Check if field is system field. | |
| EntitySchemaField & | setIsSystem (bool system) |
| Set system field flag (fluent interface). | |
| bool | isUnique () const |
| Check if field has unique constraint. | |
| EntitySchemaField & | setIsUnique (bool unique) |
| Set unique constraint (fluent interface). | |
| bool | isForeignKey () const |
| Check if field is a foreign key. | |
| std::string | foreignKeyTable () const |
| Get foreign key reference table name. | |
| std::string | foreignKeyColumn () const |
| Get foreign key reference column name. | |
| std::string | foreignKeyOnUpdate () const |
| Get foreign key update policy. | |
| std::string | foreignKeyOnDelete () const |
| Get foreign key delete policy. | |
| EntitySchemaField & | setForeignKey (const std::string &table, const std::string &column="id", const std::string &onUpdate="RESTRICT", const std::string &onDelete="RESTRICT") |
| Set foreign key reference (fluent interface). | |
| EntitySchemaField & | removeForeignKey () |
| Remove foreign key constraint (fluent interface). | |
| nlohmann::json | constraints () const |
| Get all field constraints. | |
| nlohmann::json | constraint (const std::string &key) const |
| Get specific constraint by key. | |
| EntitySchemaField & | setConstraints (const nlohmann::json &opts) |
| Set field constraints (fluent interface). | |
| EntitySchemaField & | updateWith (const nlohmann::json &field_schema) |
| Update field with new JSON data. | |
| nlohmann::json | toJSON () const |
| Convert field to JSON representation. | |
| soci::db_type | toSociType () const |
| Convert field type to SOCI database type. | |
| std::optional< std::string > | validate () const |
| Validate field definition. | |
Static Public Member Functions | |
| static const std::vector< std::string > & | defaultBaseFields () |
| static const std::vector< std::string > & | defaultAuthFields () |
| static const std::vector< std::string > & | defaultEntityFieldTypes () |
| static soci::db_type | toSociType (const std::string &type) |
| Convert type string to SOCI database type (static). | |
| static bool | isValidFieldType (const std::string &type) |
| Check if field type is valid. | |
| static std::string | genFieldId (const std::string &id) |
| Generate unique field ID from name. | |
| static const nlohmann::json & | defaultConstraints () |
| Get default constraints JSON. | |
Represents a single field in a database table schema.
Defines field properties including name, type, constraints, and validation rules. Supports fluent interface for building field definitions.
| mb::EntitySchemaField::EntitySchemaField | ( | std::string | field_name, |
| std::string | field_type | ||
| ) |
Construct field with name and type.
| field_name | Field name |
| field_type | Field type (e.g., "string", "int32", "bool", "date") |
|
explicit |
Construct field from JSON schema object.
| field_schema | JSON object with field definition |
|
default |
| nlohmann::json mb::EntitySchemaField::constraint | ( | const std::string & | key | ) | const |
Get specific constraint by key.
| key | Constraint key (e.g., "min", "max", "validator") |
| nlohmann::json mb::EntitySchemaField::constraints | ( | ) | const |
Get all field constraints.
|
static |
|
static |
|
static |
Get default constraints JSON.
|
static |
| std::string mb::EntitySchemaField::foreignKeyColumn | ( | ) | const |
Get foreign key reference column name.
| std::string mb::EntitySchemaField::foreignKeyOnDelete | ( | ) | const |
Get foreign key delete policy.
| std::string mb::EntitySchemaField::foreignKeyOnUpdate | ( | ) | const |
Get foreign key update policy.
| std::string mb::EntitySchemaField::foreignKeyTable | ( | ) | const |
Get foreign key reference table name.
|
static |
Generate unique field ID from name.
| id | Field name or identifier |
| std::string mb::EntitySchemaField::id | ( | ) | const |
Get field unique identifier.
| bool mb::EntitySchemaField::isForeignKey | ( | ) | const |
Check if field is a foreign key.
| bool mb::EntitySchemaField::isPrimaryKey | ( | ) | const |
Check if field is primary key.
| bool mb::EntitySchemaField::isSystem | ( | ) | const |
Check if field is system field.
| bool mb::EntitySchemaField::isUnique | ( | ) | const |
Check if field has unique constraint.
|
static |
Check if field type is valid.
| type | Type string to validate |
| std::string mb::EntitySchemaField::name | ( | ) | const |
Get field name.
| bool mb::EntitySchemaField::operator== | ( | const EntitySchemaField & | other | ) | const |
| EntitySchemaField & mb::EntitySchemaField::removeForeignKey | ( | ) |
Remove foreign key constraint (fluent interface).
| bool mb::EntitySchemaField::required | ( | ) | const |
Check if field is required.
| EntitySchemaField & mb::EntitySchemaField::setConstraints | ( | const nlohmann::json & | opts | ) |
Set field constraints (fluent interface).
| opts | JSON object with constraint values |
| EntitySchemaField & mb::EntitySchemaField::setForeignKey | ( | const std::string & | table, |
| const std::string & | column = "id", |
||
| const std::string & | onUpdate = "RESTRICT", |
||
| const std::string & | onDelete = "RESTRICT" |
||
| ) |
Set foreign key reference (fluent interface).
| table | Reference table name |
| column | Reference column name (defaults to "id") |
| onUpdate | Update policy (defaults to "RESTRICT") |
| onDelete | Delete policy (defaults to "RESTRICT") |
| EntitySchemaField & mb::EntitySchemaField::setIsPrimaryKey | ( | bool | pk | ) |
Set primary key flag (fluent interface).
| pk | Primary key flag |
| EntitySchemaField & mb::EntitySchemaField::setIsSystem | ( | bool | system | ) |
Set system field flag (fluent interface).
| system | System field flag |
| EntitySchemaField & mb::EntitySchemaField::setIsUnique | ( | bool | unique | ) |
Set unique constraint (fluent interface).
| unique | Unique flag |
| EntitySchemaField & mb::EntitySchemaField::setName | ( | const std::string & | name | ) |
Set field name (fluent interface).
| name | New field name |
| EntitySchemaField & mb::EntitySchemaField::setRequired | ( | bool | required | ) |
Set required flag (fluent interface).
| required | Required flag |
| EntitySchemaField & mb::EntitySchemaField::setType | ( | const std::string & | type | ) |
Set field type (fluent interface).
| type | Field type (e.g., "string", "int32", "bool") |
| nlohmann::json mb::EntitySchemaField::toJSON | ( | ) | const |
Convert field to JSON representation.
| soci::db_type mb::EntitySchemaField::toSociType | ( | ) | const |
Convert field type to SOCI database type.
|
static |
Convert type string to SOCI database type (static).
| type | Field type string |
| std::string mb::EntitySchemaField::type | ( | ) | const |
Get field type.
| EntitySchemaField & mb::EntitySchemaField::updateWith | ( | const nlohmann::json & | field_schema | ) |
Update field with new JSON data.
| field_schema | JSON object with field updates |
| std::optional< std::string > mb::EntitySchemaField::validate | ( | ) | const |
Validate field definition.