|
MantisBase v0.3.4
|
Represents a database table/entity with schema and CRUD operations. More...
#include <entity.h>
Public Member Functions | |
| Entity (const nlohmann::json &schema) | |
| Construct entity from schema JSON object. | |
| Entity (const std::string &name, const std::string &type) | |
| Construct entity with name and type. | |
| std::string | id () const |
| Get entity unique identifier. | |
| std::string | name () const |
| Get entity table name. | |
| std::string | type () const |
| Get entity type ("base", "auth", or "view"). | |
| bool | isSystem () const |
| Check if entity is a system table. | |
| bool | hasApi () const |
| Check if entity has API endpoints enabled. | |
| std::string | viewQuery () const |
| Get SQL query for view type entities. | |
| const std::vector< json > & | fields () const |
| Get all field definitions. | |
| std::optional< json > | field (const std::string &field_name) const |
| Get field definition by name. | |
| std::optional< json > | hasField (const std::string &field_name) const |
| Check if field exists by name. | |
| const json & | rules () const |
| Get all access rules. | |
| AccessRule | listRule () const |
| Get list access rule (for GET /api/v1/entities/{table}). | |
| AccessRule | getRule () const |
| Get read access rule (for GET /api/v1/entities/{table}/:id). | |
| AccessRule | addRule () const |
| Get create access rule (for POST /api/v1/entities/{table}). | |
| AccessRule | updateRule () const |
| Get update access rule (for PATCH /api/v1/entities/{table}/:id). | |
| AccessRule | deleteRule () const |
| Get delete access rule (for DELETE /api/v1/entities/{table}/:id). | |
| Record | create (const json &record, const json &opts=json::object()) const |
| Create a new record in the entity table. | |
| Records | list (const json &opts=json::object()) const |
| List all records in the entity table. | |
| std::optional< Record > | read (const std::string &id, const json &opts=json::object()) const |
| Read a single record by ID. | |
| Record | update (const std::string &id, const json &data, const json &opts=json::object()) const |
| Update an existing record by ID. | |
| void | remove (const std::string &id) const |
| Delete a record by ID. | |
| const json & | schema () const |
| Get complete entity schema JSON. | |
| int | countRecords () const |
| Count total records in the entity table. | |
| bool | isEmpty () const |
| Check if entity table is empty. | |
| bool | recordExists (const std::string &id) const |
| Check if a record exists by ID. | |
| std::optional< json > | findField (const std::string &field_name) const |
| Find field definition by name (alias for field()). | |
| std::optional< json > | queryFromCols (const std::string &value, const std::vector< std::string > &columns) const |
| Query records by searching across multiple columns. | |
| HandlerFn | getOneRouteHandler () const |
| Get route handler for GET /api/v1/entities/{table}/:id. | |
| HandlerFn | getManyRouteHandler () const |
| Get route handler for GET /api/v1/entities/{table}. | |
| HandlerWithContentReaderFn | postRouteHandler () const |
| Get route handler for POST /api/v1/entities/{table}. | |
| HandlerWithContentReaderFn | patchRouteHandler () const |
| Get route handler for PATCH /api/v1/entities/{table}/:id. | |
| HandlerFn | deleteRouteHandler () const |
| Get route handler for DELETE /api/v1/entities/{table}/:id. | |
| void | createEntityRoutes () const |
| Register all CRUD routes for this entity with the router. | |
Represents a database table/entity with schema and CRUD operations.
Entity provides methods to interact with database tables including creating, reading, updating, and deleting records. It encapsulates schema information and access rules.
|
explicit |
Construct entity from schema JSON object.
| schema | JSON object containing table schema (name, type, fields, rules, etc.) |
|
explicit |
Construct entity with name and type.
| name | Table name |
| type | Entity type ("base", "auth", or "view") |
| AccessRule mb::Entity::addRule | ( | ) | const |
Get create access rule (for POST /api/v1/entities/{table}).
| int mb::Entity::countRecords | ( | ) | const |
Count total records in the entity table.
Create a new record in the entity table.
| record | JSON object with field values |
| opts | Optional parameters (currently unused) |
| void mb::Entity::createEntityRoutes | ( | ) | const |
Register all CRUD routes for this entity with the router.
| HandlerFn mb::Entity::deleteRouteHandler | ( | ) | const |
Get route handler for DELETE /api/v1/entities/{table}/:id.
| AccessRule mb::Entity::deleteRule | ( | ) | const |
Get delete access rule (for DELETE /api/v1/entities/{table}/:id).
| std::optional< json > mb::Entity::field | ( | const std::string & | field_name | ) | const |
Get field definition by name.
| field_name | Field name to lookup |
| const std::vector< json > & mb::Entity::fields | ( | ) | const |
Get all field definitions.
| std::optional< json > mb::Entity::findField | ( | const std::string & | field_name | ) | const |
Find field definition by name (alias for field()).
| field_name | Field name to find |
| HandlerFn mb::Entity::getManyRouteHandler | ( | ) | const |
Get route handler for GET /api/v1/entities/{table}.
| HandlerFn mb::Entity::getOneRouteHandler | ( | ) | const |
Get route handler for GET /api/v1/entities/{table}/:id.
| AccessRule mb::Entity::getRule | ( | ) | const |
Get read access rule (for GET /api/v1/entities/{table}/:id).
| bool mb::Entity::hasApi | ( | ) | const |
Check if entity has API endpoints enabled.
| std::optional< json > mb::Entity::hasField | ( | const std::string & | field_name | ) | const |
Check if field exists by name.
| field_name | Field name to check |
| std::string mb::Entity::id | ( | ) | const |
Get entity unique identifier.
| bool mb::Entity::isEmpty | ( | ) | const |
Check if entity table is empty.
| bool mb::Entity::isSystem | ( | ) | const |
Check if entity is a system table.
List all records in the entity table.
| opts | Optional parameters (currently unused) |
| AccessRule mb::Entity::listRule | ( | ) | const |
Get list access rule (for GET /api/v1/entities/{table}).
| std::string mb::Entity::name | ( | ) | const |
Get entity table name.
| HandlerWithContentReaderFn mb::Entity::patchRouteHandler | ( | ) | const |
Get route handler for PATCH /api/v1/entities/{table}/:id.
| HandlerWithContentReaderFn mb::Entity::postRouteHandler | ( | ) | const |
Get route handler for POST /api/v1/entities/{table}.
| std::optional< json > mb::Entity::queryFromCols | ( | const std::string & | value, |
| const std::vector< std::string > & | columns | ||
| ) | const |
Query records by searching across multiple columns.
| value | Value to search for |
| columns | Column names to search in |
| std::optional< Record > mb::Entity::read | ( | const std::string & | id, |
| const json & | opts = json::object() |
||
| ) | const |
Read a single record by ID.
| id | Record identifier |
| opts | Optional parameters (currently unused) |
| bool mb::Entity::recordExists | ( | const std::string & | id | ) | const |
Check if a record exists by ID.
| id | Record identifier to check |
| void mb::Entity::remove | ( | const std::string & | id | ) | const |
Delete a record by ID.
| id | Record identifier to delete |
| const json & mb::Entity::rules | ( | ) | const |
Get all access rules.
| const json & mb::Entity::schema | ( | ) | const |
Get complete entity schema JSON.
| std::string mb::Entity::type | ( | ) | const |
Get entity type ("base", "auth", or "view").
| Record mb::Entity::update | ( | const std::string & | id, |
| const json & | data, | ||
| const json & | opts = json::object() |
||
| ) | const |
Update an existing record by ID.
| id | Record identifier |
| data | JSON object with fields to update |
| opts | Optional parameters (currently unused) |
| AccessRule mb::Entity::updateRule | ( | ) | const |
Get update access rule (for PATCH /api/v1/entities/{table}/:id).
| std::string mb::Entity::viewQuery | ( | ) | const |
Get SQL query for view type entities.
| MantisException | if entity is not a view type |