MantisBase v0.4.9
Loading...
Searching...
No Matches
mb::MbEntitySchemaField Class Reference

#include <entity_schema_field.h>

Public Member Functions

 MbEntitySchemaField (std::string field_name, std::string field_type)
 MbEntitySchemaField (const nlohmann::json &field_schema)
 Construct field from JSON schema object.
 MbEntitySchemaField (const MbEntitySchemaField &other)
bool operator== (const MbEntitySchemaField &other) const
std::string id () const
 Get field unique identifier.
std::string name () const
 Get field name.
MbEntitySchemaField & setName (const std::string &name)
 Set field name (fluent interface).
std::string type () const
 Get field type.
MbEntitySchemaField & setType (const std::string &type)
MbIntPrecision intPrecision () const
MbEntitySchemaField & setIntPrecision (MbIntPrecision precision)
MbEntitySchemaField & setPrecision (const std::string &precision)
bool required () const
 Check if field is required.
MbEntitySchemaField & setRequired (bool required)
 Set required flag (fluent interface).
bool isPrimaryKey () const
 Check if field is primary key.
MbEntitySchemaField & setIsPrimaryKey (bool pk)
 Set primary key flag (fluent interface).
bool isSystem () const
 Check if field is system field.
MbEntitySchemaField & setIsSystem (bool system)
 Set system field flag (fluent interface).
bool isUnique () const
 Check if field has unique constraint.
MbEntitySchemaField & 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.
MbEntitySchemaField & 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).
MbEntitySchemaField & 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.
MbEntitySchemaField & setConstraints (const nlohmann::json &opts)
 Set field constraints (fluent interface).
MbEntitySchemaField & 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)
static soci::db_type toSociType (const std::string &type, MbIntPrecision precision)
static bool isValidFieldType (const std::string &type)
 Check if field type is valid.
static bool isValidFieldName (const std::string &name)
static std::string genFieldId (const std::string &id)
 Generate unique field ID from name.
static const nlohmann::json & defaultConstraints ()
 Get default constraints JSON.

Constructor & Destructor Documentation

◆ MbEntitySchemaField() [1/3]

mb::MbEntitySchemaField::MbEntitySchemaField ( std::string field_name,
std::string field_type )

◆ MbEntitySchemaField() [2/3]

mb::MbEntitySchemaField::MbEntitySchemaField ( const nlohmann::json & field_schema)
explicit

Construct field from JSON schema object.

Parameters
field_schemaJSON object with field definition

◆ MbEntitySchemaField() [3/3]

mb::MbEntitySchemaField::MbEntitySchemaField ( const MbEntitySchemaField & other)
default

Member Function Documentation

◆ constraint()

nlohmann::json mb::MbEntitySchemaField::constraint ( const std::string & key) const
nodiscard

Get specific constraint by key.

Parameters
keyConstraint key (e.g., "min", "max", "validator")
Returns
Constraint value JSON

◆ constraints()

nlohmann::json mb::MbEntitySchemaField::constraints ( ) const
nodiscard

Get all field constraints.

Returns
JSON object with constraints (min, max, validator, etc.)

◆ defaultAuthFields()

const std::vector< std::string > & mb::MbEntitySchemaField::defaultAuthFields ( )
static
Returns
Default auth entity field names (includes password/email fields).

◆ defaultBaseFields()

const std::vector< std::string > & mb::MbEntitySchemaField::defaultBaseFields ( )
static
Returns
Default base entity field names (id, created, updated).

◆ defaultConstraints()

const nlohmann::json & mb::MbEntitySchemaField::defaultConstraints ( )
static

Get default constraints JSON.

Returns
Reference to default constraints object

◆ defaultEntityFieldTypes()

const std::vector< std::string > & mb::MbEntitySchemaField::defaultEntityFieldTypes ( )
static
Returns
Supported entity field type strings.

◆ foreignKeyColumn()

std::string mb::MbEntitySchemaField::foreignKeyColumn ( ) const
nodiscard

Get foreign key reference column name.

Returns
Reference column name, defaults to "id" if not specified

◆ foreignKeyOnDelete()

std::string mb::MbEntitySchemaField::foreignKeyOnDelete ( ) const
nodiscard

Get foreign key delete policy.

Returns
Delete policy ("CASCADE", "SET NULL", "RESTRICT", "NO ACTION", "SET DEFAULT")

◆ foreignKeyOnUpdate()

std::string mb::MbEntitySchemaField::foreignKeyOnUpdate ( ) const
nodiscard

Get foreign key update policy.

Returns
Update policy ("CASCADE", "SET NULL", "RESTRICT", "NO ACTION", "SET DEFAULT")

◆ foreignKeyTable()

std::string mb::MbEntitySchemaField::foreignKeyTable ( ) const
nodiscard

Get foreign key reference table name.

Returns
Reference table name, empty if not a foreign key

◆ genFieldId()

std::string mb::MbEntitySchemaField::genFieldId ( const std::string & id)
static

Generate unique field ID from name.

Parameters
idField name or identifier
Returns
Generated field ID string

◆ id()

std::string mb::MbEntitySchemaField::id ( ) const
nodiscard

Get field unique identifier.

Returns
Field ID string

◆ intPrecision()

MbIntPrecision mb::MbEntitySchemaField::intPrecision ( ) const
nodiscard
Returns
Int storage precision for int-typed fields.

◆ isForeignKey()

bool mb::MbEntitySchemaField::isForeignKey ( ) const
nodiscard

Check if field is a foreign key.

Returns
true if foreign key

◆ isPrimaryKey()

bool mb::MbEntitySchemaField::isPrimaryKey ( ) const
nodiscard

Check if field is primary key.

Returns
true if primary key

◆ isSystem()

bool mb::MbEntitySchemaField::isSystem ( ) const
nodiscard

Check if field is system field.

Returns
true if system field

◆ isUnique()

bool mb::MbEntitySchemaField::isUnique ( ) const
nodiscard

Check if field has unique constraint.

Returns
true if unique

◆ isValidFieldName()

bool mb::MbEntitySchemaField::isValidFieldName ( const std::string & name)
static
Returns
true if name is a valid SQL-safe field identifier.

◆ isValidFieldType()

bool mb::MbEntitySchemaField::isValidFieldType ( const std::string & type)
static

Check if field type is valid.

Parameters
typeType string to validate
Returns
true if valid type

◆ name()

std::string mb::MbEntitySchemaField::name ( ) const
nodiscard

Get field name.

Returns
Field name

◆ operator==()

bool mb::MbEntitySchemaField::operator== ( const MbEntitySchemaField & other) const

◆ removeForeignKey()

MbEntitySchemaField & mb::MbEntitySchemaField::removeForeignKey ( )

Remove foreign key constraint (fluent interface).

Returns
Reference to self for chaining

◆ required()

bool mb::MbEntitySchemaField::required ( ) const
nodiscard

Check if field is required.

Returns
true if required

◆ setConstraints()

MbEntitySchemaField & mb::MbEntitySchemaField::setConstraints ( const nlohmann::json & opts)

Set field constraints (fluent interface).

Parameters
optsJSON object with constraint values
Returns
Reference to self for chaining

◆ setForeignKey()

MbEntitySchemaField & mb::MbEntitySchemaField::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).

Parameters
tableReference table name
columnReference column name (defaults to "id")
onUpdateUpdate policy (defaults to "RESTRICT")
onDeleteDelete policy (defaults to "RESTRICT")
Returns
Reference to self for chaining

◆ setIntPrecision()

MbEntitySchemaField & mb::MbEntitySchemaField::setIntPrecision ( MbIntPrecision precision)

◆ setIsPrimaryKey()

MbEntitySchemaField & mb::MbEntitySchemaField::setIsPrimaryKey ( bool pk)

Set primary key flag (fluent interface).

Parameters
pkPrimary key flag
Returns
Reference to self for chaining

◆ setIsSystem()

MbEntitySchemaField & mb::MbEntitySchemaField::setIsSystem ( bool system)

Set system field flag (fluent interface).

Parameters
systemSystem field flag
Returns
Reference to self for chaining

◆ setIsUnique()

MbEntitySchemaField & mb::MbEntitySchemaField::setIsUnique ( bool unique)

Set unique constraint (fluent interface).

Parameters
uniqueUnique flag
Returns
Reference to self for chaining

◆ setName()

MbEntitySchemaField & mb::MbEntitySchemaField::setName ( const std::string & name)

Set field name (fluent interface).

Parameters
nameNew field name
Returns
Reference to self for chaining

◆ setPrecision()

MbEntitySchemaField & mb::MbEntitySchemaField::setPrecision ( const std::string & precision)

Set precision from string token (i32, u64, …).

◆ setRequired()

MbEntitySchemaField & mb::MbEntitySchemaField::setRequired ( bool required)

Set required flag (fluent interface).

Parameters
requiredRequired flag
Returns
Reference to self for chaining

◆ setType()

MbEntitySchemaField & mb::MbEntitySchemaField::setType ( const std::string & type)

Set field type (fluent).

Returns
Reference to self.

◆ toJSON()

nlohmann::json mb::MbEntitySchemaField::toJSON ( ) const
nodiscard

Convert field to JSON representation.

Returns
JSON object with field definition

◆ toSociType() [1/3]

soci::db_type mb::MbEntitySchemaField::toSociType ( ) const
nodiscard

Convert field type to SOCI database type.

Returns
SOCI db_type enum value

◆ toSociType() [2/3]

soci::db_type mb::MbEntitySchemaField::toSociType ( const std::string & type)
staticnodiscard

Map a type string to SOCI db_type (non-int types).

◆ toSociType() [3/3]

soci::db_type mb::MbEntitySchemaField::toSociType ( const std::string & type,
MbIntPrecision precision )
staticnodiscard

Map int type + precision to SOCI db_type.

◆ type()

std::string mb::MbEntitySchemaField::type ( ) const
nodiscard

Get field type.

Returns
Field type string

◆ updateWith()

MbEntitySchemaField & mb::MbEntitySchemaField::updateWith ( const nlohmann::json & field_schema)

Update field with new JSON data.

Parameters
field_schemaJSON object with field updates
Returns
Reference to self for chaining

◆ validate()

std::optional< std::string > mb::MbEntitySchemaField::validate ( ) const
nodiscard

Validate field definition.

Returns
Optional error message if validation fails

The documentation for this class was generated from the following files: