Nextcloud PHP API (stable19)

QBMapper

Simple parent class for inheriting your data access layer from. This class may be subject to change in the future

Tags
since
14.0.0
template

T of Entity

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

$entityClass

protected string|class-string<\OCP\AppFramework\Db\T> $entityClass

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
psalm-param

class-string<T>|null $entityClass the name of the entity that the sql should be mapped to queries without using sql

since
14.0.0
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
psalm-param

T $entity the entity that should be deleted

psalm-return

T the deleted entity

since
14.0.0
Return values
Entity —

the deleted entity

getTableName()

public getTableName() : string
Tags
since
14.0.0
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
psalm-param

T $entity the entity that should be created

psalm-return

T the saved entity with the set id

since
14.0.0
suppress

SqlInjectionChecker

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
psalm-param

T $entity the entity that should be created/updated

psalm-return

T the saved entity with the (new) id

throws
InvalidArgumentException

if entity has no id

since
15.0.0
suppress

SqlInjectionChecker

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
throws
InvalidArgumentException

if entity has no id

psalm-param

T $entity the entity that should be created

psalm-return

T the saved entity with the set id

since
14.0.0
suppress

SqlInjectionChecker

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
psalm-return

T[] all fetched entities

since
14.0.0
Return values
\OCP\AppFramework\Db\Entity[] —

all fetched entities

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
psalm-param

T $entity

since
16.0.0
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
psalm-return

T the entity

since
14.0.0
Return values
Entity —

the entity

buildDebugMessage()

private buildDebugMessage(string $msg, IQueryBuilder $sql) : string
Parameters
$msg : string
$sql : IQueryBuilder
Tags
since
14.0.0
Return values
string —

Search results