QBMapper
in package
Simple parent class for inheriting your data access layer from. This class may be subject to change in the future
Tags
Table of Contents
Properties
- $db : IDBConnection
- $entityClass : string|T>
- $tableName : string
Methods
- __construct() : mixed
- delete() : Entity
- Deletes an entity from the table
- getTableName() : string
- insert() : Entity
- Creates a new entry in the db from an entity
- insertOrUpdate() : Entity
- Tries to creates a new entry in the db from an entity and updates an existing entry if duplicate keys are detected by the database
- update() : Entity
- Updates an entry in the db from an entity
- findEntities() : array<int, Entity>
- Runs a sql query and returns an array of entities
- findEntity() : Entity
- Returns an db result and throws exceptions when there are more or less results
- findOneQuery() : array<string|int, mixed>
- Returns an db result and throws exceptions when there are more or less results
- getParameterTypeForProperty() : int|string
- Returns the type parameter for the QueryBuilder for a specific property of the $entity
- mapRowToEntity() : Entity
- Creates an entity from a row. Automatically determines the entity class from the current mapper name (MyEntityMapper -> MyEntity)
- yieldEntities() : Generator
- Runs a sql query and yields each resulting entity to obtain database entries in a memory-efficient way
- buildDebugMessage() : string
Properties
$db
protected
IDBConnection
$db
$entityClass
protected
string|T>
$entityClass
$tableName
protected
string
$tableName
Methods
__construct()
public
__construct(IDBConnection $db, string $tableName[, T>|null $entityClass = null ]) : mixed
Parameters
- $db : IDBConnection
-
Instance of the Db abstraction layer
- $tableName : string
-
the name of the table. set this to allow entity
- $entityClass : T>|null = null
-
the name of the entity that the sql should be mapped to queries without using sql
Tags
delete()
Deletes an entity from the table
public
delete(Entity $entity) : Entity
Parameters
- $entity : Entity
-
the entity that should be deleted
Tags
Return values
Entity —the deleted entity
getTableName()
public
getTableName() : string
Tags
Return values
string —the table name
insert()
Creates a new entry in the db from an entity
public
insert(Entity $entity) : Entity
Parameters
- $entity : Entity
-
the entity that should be created
Tags
Return values
Entity —the saved entity with the set id
insertOrUpdate()
Tries to creates a new entry in the db from an entity and updates an existing entry if duplicate keys are detected by the database
public
insertOrUpdate(Entity $entity) : Entity
Parameters
- $entity : Entity
-
the entity that should be created/updated
Tags
Return values
Entity —the saved entity with the (new) id
update()
Updates an entry in the db from an entity
public
update(Entity $entity) : Entity
Parameters
- $entity : Entity
-
the entity that should be created
Tags
Return values
Entity —the saved entity with the set id
findEntities()
Runs a sql query and returns an array of entities
protected
findEntities(IQueryBuilder $query) : array<int, Entity>
Parameters
- $query : IQueryBuilder
Tags
Return values
array<int, Entity> —all fetched entities
findEntity()
Returns an db result and throws exceptions when there are more or less results
protected
findEntity(IQueryBuilder $query) : Entity
Parameters
- $query : IQueryBuilder
Tags
Return values
Entity —the entity
findOneQuery()
Returns an db result and throws exceptions when there are more or less results
protected
findOneQuery(IQueryBuilder $query) : array<string|int, mixed>
Parameters
- $query : IQueryBuilder
Tags
Return values
array<string|int, mixed> —the result as row
getParameterTypeForProperty()
Returns the type parameter for the QueryBuilder for a specific property of the $entity
protected
getParameterTypeForProperty(Entity $entity, string $property) : int|string
Parameters
- $entity : Entity
-
The entity to get the types from
- $property : string
-
The property of $entity to get the type for
Tags
Return values
int|stringmapRowToEntity()
Creates an entity from a row. Automatically determines the entity class from the current mapper name (MyEntityMapper -> MyEntity)
protected
mapRowToEntity(array<string|int, mixed> $row) : Entity
Parameters
- $row : array<string|int, mixed>
-
the row which should be converted to an entity
Tags
Return values
Entity —the entity
yieldEntities()
Runs a sql query and yields each resulting entity to obtain database entries in a memory-efficient way
protected
yieldEntities(IQueryBuilder $query) : Generator
Parameters
- $query : IQueryBuilder
Tags
Return values
Generator —Generator of fetched entities
buildDebugMessage()
private
buildDebugMessage(string $msg, IQueryBuilder $sql) : string
Parameters
- $msg : string
- $sql : IQueryBuilder