QBMapper
Simple parent class for inheriting your data access layer from. This class may be subject to change in the future
Tags
Table of Contents
- $db : IDBConnection
- $entityClass : string|class-string<\OCP\AppFramework\Db\T>
- $tableName : string
- __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() : \OCP\AppFramework\Db\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
- Returns an db result and throws exceptions when there are more or less results
- getParameterTypeForProperty() : int
- 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)
- buildDebugMessage() : string
Properties
$db
protected
IDBConnection
$db
$entityClass
protected
string|class-string<\OCP\AppFramework\Db\T>
$entityClass
$tableName
protected
string
$tableName
Methods
__construct()
public
__construct(IDBConnection $db, string $tableName[, string|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 : string|null = null
-
the name of the entity that the sql should be
Tags
Return values
mixed —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) : \OCP\AppFramework\Db\Entity[]
Parameters
- $query : IQueryBuilder
Tags
Return values
\OCP\AppFramework\Db\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
Parameters
- $query : IQueryBuilder
Tags
Return values
array —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
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 —mapRowToEntity()
Creates an entity from a row. Automatically determines the entity class from the current mapper name (MyEntityMapper -> MyEntity)
protected
mapRowToEntity(array $row) : Entity
Parameters
- $row : array
-
the row which should be converted to an entity
Tags
Return values
Entity —the entity
buildDebugMessage()
private
buildDebugMessage(string $msg, IQueryBuilder $sql) : string
Parameters
- $msg : string
- $sql : IQueryBuilder