Nextcloud PHP API (master)

QBMapper
in package

AbstractYes

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

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

$entityClass

protected string|T> $entityClass

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

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

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

throws
Exception
since
14.0.0
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
Exception
throws
InvalidArgumentException

if entity has no id

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

T $entity the entity that should be created

psalm-return

T the saved entity with the set id

throws
Exception
throws
InvalidArgumentException

if entity has no id

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

list<T> all fetched entities

throws
Exception
since
14.0.0
Return values
array<int, 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|string
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|string

mapRowToEntity()

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

T the entity

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

Generator<T> Generator of fetched entities

throws
Exception
since
30.0.0
Return values
Generator

Generator of fetched entities

buildDebugMessage()

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

        
On this page

Search results