Nextcloud PHP API (stable18)

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

Table of Contents

$db  : IDBConnection
$entityClass  : string
$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 $entityClass

Methods

__construct()

public __construct(IDBConnection $db, string $tableName[, string $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

the name of the entity that the sql should be mapped to queries without using sql

Tags
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
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
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
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

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