|
MantisBase v0.3.4
|
Builder class for creating and managing database table schemas. More...
#include <entity_schema.h>
Public Member Functions | |
| EntitySchema ()=default | |
| Default constructor (creates empty schema). | |
| EntitySchema (const std::string &entity_name, const std::string &entity_type="base") | |
| Construct schema with name and type. | |
| EntitySchema (const EntitySchema &) | |
| EntitySchema & | operator= (const EntitySchema &) |
| EntitySchema (EntitySchema &&) noexcept=default | |
| EntitySchema & | operator= (EntitySchema &&) noexcept=default |
| ~EntitySchema () | |
| bool | operator== (const EntitySchema &other) const |
| Compare two schemas for equality. | |
| Entity | toEntity () const |
| Convert schema to Entity for database operations. | |
| std::string | id () const |
| Get schema unique identifier. | |
| std::string | name () const |
| Get table name. | |
| EntitySchema & | setName (const std::string &name) |
| Set table name (fluent interface). | |
| std::string | type () const |
| Get entity type. | |
| EntitySchema & | setType (const std::string &type) |
| Set entity type (fluent interface). | |
| bool | hasApi () const |
| Check if API endpoints are enabled. | |
| EntitySchema & | setHasApi (const bool &hasApi) |
| Enable/disable API endpoints (fluent interface). | |
| bool | isSystem () const |
| Check if this is a system table. | |
| EntitySchema & | setSystem (const bool &isSystem) |
| Set system table flag (fluent interface). | |
| AccessRule | listRule () const |
| EntitySchema & | setListRule (const AccessRule &listRule) |
| AccessRule | getRule () const |
| EntitySchema & | setGetRule (const AccessRule &getRule) |
| AccessRule | addRule () const |
| EntitySchema & | setAddRule (const AccessRule &addRule) |
| AccessRule | updateRule () const |
| EntitySchema & | setUpdateRule (const AccessRule &updateRule) |
| AccessRule | deleteRule () const |
| EntitySchema & | setDeleteRule (const AccessRule &deleteRule) |
| std::vector< EntitySchemaField > | fields () const |
| Get all field definitions. | |
| EntitySchema & | addField (const EntitySchemaField &field) |
| Add a field to the schema (fluent interface). | |
| bool | removeField (const std::string &field_name) |
| Remove a field by name. | |
| EntitySchemaField & | field (const std::string &field_name) |
| Get field by name (mutable reference). | |
| EntitySchemaField & | fieldById (const std::string &field_id) |
| Get field by ID (mutable reference). | |
| bool | hasField (const std::string &field_name) const |
| Check if field exists by name. | |
| bool | hasFieldById (const std::string &field_id) const |
| Check if field exists by ID. | |
| std::string | viewQuery () const |
| Get SQL query for view type entities. | |
| EntitySchema & | setViewQuery (const std::string &viewQuery) |
| Set SQL query for view type (fluent interface). | |
| void | updateWith (const nlohmann::json &new_data) |
| Update schema with new JSON data (merges fields). | |
| json | toJSON () const |
| Convert schema to JSON representation. | |
| std::string | toDDL () const |
| Generate SQL DDL (CREATE TABLE) statement. | |
| std::string | dump () const |
| Dump schema as formatted string (for debugging). | |
| std::optional< std::string > | validate () const |
| Validate this schema instance. | |
| HandlerFn | getOneRouteHandler () const |
| HandlerFn | getManyRouteHandler () const |
| HandlerFn | postRouteHandler () const |
| HandlerFn | patchRouteHandler () const |
| HandlerFn | deleteRouteHandler () const |
| void | createEntityRoutes () const |
Static Public Member Functions | |
| static EntitySchema | fromSchema (const json &entity_schema) |
| Create schema from JSON object. | |
| static EntitySchema | fromEntity (const Entity &entity) |
| Create schema from existing Entity. | |
| static std::string | toDefaultSqlValue (const std::string &type, const nlohmann::json &v) |
| Get default SQL value for a field type. | |
| static nlohmann::json | listTables (const nlohmann::json &opts=nlohmann::json::object()) |
| List all tables from database. | |
| static nlohmann::json | getTable (const std::string &table_id) |
| Get table schema by ID from database. | |
| static nlohmann::json | createTable (const EntitySchema &new_table) |
| Create table in database from schema. | |
| static nlohmann::json | updateTable (const std::string &table_id, const nlohmann::json &new_schema) |
| Update existing table schema in database. | |
| static void | dropTable (const EntitySchema &original_table) |
| Drop table from database. | |
| static void | dropTable (const std::string &table_id) |
| Drop table by ID from database. | |
| static bool | tableExists (const std::string &table_name) |
| Check if table exists by name. | |
| static bool | tableExists (const EntitySchema &table) |
| Check if table exists (by schema name). | |
| static std::string | genEntityId (const std::string &entity_name) |
| Generate unique entity ID from name. | |
| static std::optional< std::string > | validate (const EntitySchema &table_schema) |
| Validate schema (static method). | |
| static bool | isValidEntityName (const std::string &name) |
| Validate this schema name to alphanum and _ only. | |
| static bool | isValidEntityType (const std::string &type) |
| Validate this schema type to the 3 supported types. | |
| static const std::vector< EntitySchemaField > & | defaultBaseFieldsSchema () |
| static const std::vector< EntitySchemaField > & | defaultAuthFieldsSchema () |
Builder class for creating and managing database table schemas.
EntitySchema provides a fluent interface for defining table structures, fields, access rules, and converting to/from JSON and DDL.
|
default |
Default constructor (creates empty schema).
|
explicit |
Construct schema with name and type.
| entity_name | Table name |
| entity_type | Entity type ("base", "auth", or "view"), defaults to "base" |
|
default |
|
defaultnoexcept |
|
default |
| EntitySchema & mb::EntitySchema::addField | ( | const EntitySchemaField & | field | ) |
Add a field to the schema (fluent interface).
| field | Field to add |
| AccessRule mb::EntitySchema::addRule | ( | ) | const |
| void mb::EntitySchema::createEntityRoutes | ( | ) | const |
|
static |
Create table in database from schema.
| new_table | Schema to create |
|
static |
|
static |
| HandlerFn mb::EntitySchema::deleteRouteHandler | ( | ) | const |
| AccessRule mb::EntitySchema::deleteRule | ( | ) | const |
|
static |
Drop table from database.
| original_table | Schema of table to drop |
|
static |
Drop table by ID from database.
| table_id | Table identifier to drop |
| std::string mb::EntitySchema::dump | ( | ) | const |
Dump schema as formatted string (for debugging).
| EntitySchemaField & mb::EntitySchema::field | ( | const std::string & | field_name | ) |
Get field by name (mutable reference).
| field_name | Field name to lookup |
| std::runtime_error | if field not found |
| EntitySchemaField & mb::EntitySchema::fieldById | ( | const std::string & | field_id | ) |
Get field by ID (mutable reference).
| field_id | Field ID to lookup |
| std::runtime_error | if field not found |
| std::vector< EntitySchemaField > mb::EntitySchema::fields | ( | ) | const |
Get all field definitions.
|
static |
Create schema from existing Entity.
| entity | Entity to convert from |
|
static |
Create schema from JSON object.
| entity_schema | JSON schema object |
|
static |
| HandlerFn mb::EntitySchema::getManyRouteHandler | ( | ) | const |
| HandlerFn mb::EntitySchema::getOneRouteHandler | ( | ) | const |
| AccessRule mb::EntitySchema::getRule | ( | ) | const |
|
static |
Get table schema by ID from database.
| table_id | Table identifier |
| bool mb::EntitySchema::hasApi | ( | ) | const |
Check if API endpoints are enabled.
| bool mb::EntitySchema::hasField | ( | const std::string & | field_name | ) | const |
Check if field exists by name.
| field_name | Field name to check |
| bool mb::EntitySchema::hasFieldById | ( | const std::string & | field_id | ) | const |
Check if field exists by ID.
| field_id | Field ID to check |
| std::string mb::EntitySchema::id | ( | ) | const |
Get schema unique identifier.
| bool mb::EntitySchema::isSystem | ( | ) | const |
Check if this is a system table.
|
static |
Validate this schema name to alphanum and _ only.
|
static |
Validate this schema type to the 3 supported types.
| AccessRule mb::EntitySchema::listRule | ( | ) | const |
|
static |
List all tables from database.
| opts | Optional parameters (pagination, etc.) |
| std::string mb::EntitySchema::name | ( | ) | const |
Get table name.
| EntitySchema & mb::EntitySchema::operator= | ( | const EntitySchema & | other | ) |
|
defaultnoexcept |
| bool mb::EntitySchema::operator== | ( | const EntitySchema & | other | ) | const |
Compare two schemas for equality.
| other | Schema to compare with |
| HandlerFn mb::EntitySchema::patchRouteHandler | ( | ) | const |
| HandlerFn mb::EntitySchema::postRouteHandler | ( | ) | const |
| bool mb::EntitySchema::removeField | ( | const std::string & | field_name | ) |
Remove a field by name.
| field_name | Field name to remove |
| EntitySchema & mb::EntitySchema::setAddRule | ( | const AccessRule & | addRule | ) |
| EntitySchema & mb::EntitySchema::setDeleteRule | ( | const AccessRule & | deleteRule | ) |
| EntitySchema & mb::EntitySchema::setGetRule | ( | const AccessRule & | getRule | ) |
| EntitySchema & mb::EntitySchema::setHasApi | ( | const bool & | hasApi | ) |
Enable/disable API endpoints (fluent interface).
| hasApi | API enabled flag |
| EntitySchema & mb::EntitySchema::setListRule | ( | const AccessRule & | listRule | ) |
| EntitySchema & mb::EntitySchema::setName | ( | const std::string & | name | ) |
Set table name (fluent interface).
| name | New table name |
| EntitySchema & mb::EntitySchema::setSystem | ( | const bool & | isSystem | ) |
Set system table flag (fluent interface).
| isSystem | System table flag |
| EntitySchema & mb::EntitySchema::setType | ( | const std::string & | type | ) |
Set entity type (fluent interface).
| type | Entity type |
| EntitySchema & mb::EntitySchema::setUpdateRule | ( | const AccessRule & | updateRule | ) |
| EntitySchema & mb::EntitySchema::setViewQuery | ( | const std::string & | viewQuery | ) |
Set SQL query for view type (fluent interface).
| viewQuery | SQL SELECT query string |
|
static |
Check if table exists (by schema name).
| table | Schema to check |
|
static |
Check if table exists by name.
| table_name | Table name to check |
| std::string mb::EntitySchema::toDDL | ( | ) | const |
Generate SQL DDL (CREATE TABLE) statement.
|
static |
Get default SQL value for a field type.
| type | Field type string |
| v | JSON value (optional) |
| Entity mb::EntitySchema::toEntity | ( | ) | const |
| nlohmann::json mb::EntitySchema::toJSON | ( | ) | const |
Convert schema to JSON representation.
| std::string mb::EntitySchema::type | ( | ) | const |
Get entity type.
| AccessRule mb::EntitySchema::updateRule | ( | ) | const |
|
static |
Update existing table schema in database.
| table_id | Table identifier |
| new_schema | Updated schema JSON |
| void mb::EntitySchema::updateWith | ( | const nlohmann::json & | new_data | ) |
Update schema with new JSON data (merges fields).
| new_data | JSON object with updates |
| std::optional< std::string > mb::EntitySchema::validate | ( | ) | const |
Validate this schema instance.
|
static |
Validate schema (static method).
| table_schema | Schema to validate |
| std::string mb::EntitySchema::viewQuery | ( | ) | const |
Get SQL query for view type entities.