Mapper

class OCP\AppFramework\Db\Mapper
Simple parent class for inheriting your data access layer from. This class
may be subject to change in the future
Source:lib/public/AppFramework/Db/Mapper.php#39

Properties

protected static property OCP\AppFramework\Db\Mapper::$tableName
Source:lib/public/AppFramework/Db/Mapper.php#40
protected static property OCP\AppFramework\Db\Mapper::$entityClass
Source:lib/public/AppFramework/Db/Mapper.php#41
protected static property OCP\AppFramework\Db\Mapper::$db
Source:lib/public/AppFramework/Db/Mapper.php#42

Methods

public OCP\AppFramework\Db\Mapper::__construct($db, $tableName, $entityClass=null)
Source:

lib/public/AppFramework/Db/Mapper.php#52

Parameters:
  • $db (OCP\IDBConnection) Instance of the Db abstraction layer
  • $tableName (string) the name of the table. set this to allow entity
  • $entityClass (string) the name of the entity that the sql should be

mapped to queries without using sql

Since:

7.0.0

Deprecated:

14.0.0 Move over to QBMapper

public OCP\AppFramework\Db\Mapper::getTableName()
Source:lib/public/AppFramework/Db/Mapper.php#71
Returns:string the table name
Since:7.0.0
Deprecated:14.0.0 Move over to QBMapper
public OCP\AppFramework\Db\Mapper::delete($entity)
Deletes an entity from the table
Source:

lib/public/AppFramework/Db/Mapper.php#83

Parameters:
Returns:

\OCP\AppFramework\Db\Entity the deleted entity

Since:

7.0.0 - return value added in 8.1.0

Deprecated:

14.0.0 Move over to QBMapper

public OCP\AppFramework\Db\Mapper::insert($entity)
Creates a new entry in the db from an entity
Source:

lib/public/AppFramework/Db/Mapper.php#98

Parameters:
Returns:

\OCP\AppFramework\Db\Entity the saved entity with the set id

Since:

7.0.0

Deprecated:

14.0.0 Move over to QBMapper

public OCP\AppFramework\Db\Mapper::update($entity)
Updates an entry in the db from an entity
Source:

lib/public/AppFramework/Db/Mapper.php#147

Parameters:
Throws:

\InvalidArgumentException if entity has no id

Returns:

\OCP\AppFramework\Db\Entity the saved entity with the set id

Since:

7.0.0 - return value was added in 8.0.0

Deprecated:

14.0.0 Move over to QBMapper

protected OCP\AppFramework\Db\Mapper::execute($sql, $params=[], $limit=null, $offset=null)
Runs an sql query
Source:

lib/public/AppFramework/Db/Mapper.php#236

Parameters:
  • $sql (string) the prepare string
  • $params (array) the params which should replace the ? in the sql query
  • $limit (int) the maximum number of rows
  • $offset (int) from which row we want to start
Returns:

\PDOStatement the database query result

Since:

7.0.0

Deprecated:

14.0.0 Move over to QBMapper

protected OCP\AppFramework\Db\Mapper::findOneQuery($sql, $params=[], $limit=null, $offset=null)
Returns an db result and throws exceptions when there are more or less
results
Source:

lib/public/AppFramework/Db/Mapper.php#272

Parameters:
  • $sql (string) the sql query
  • $params (array) the parameters of the sql query
  • $limit (int) the maximum number of rows
  • $offset (int) from which row we want to start
See:

\OCP\AppFramework\Db\findEntity

Throws:

\OCP\AppFramework\Db\DoesNotExistException if the item does not exist

Throws:

\OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one item exist

Throws:

\OCP\AppFramework\Db\DoesNotExistException if the item does not exist

Throws:

\OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one item exist

Returns:

array the result as row

Since:

7.0.0

Deprecated:

14.0.0 Move over to QBMapper

protected OCP\AppFramework\Db\Mapper::mapRowToEntity($row)
Creates an entity from a row. Automatically determines the entity class
from the current mapper name (MyEntityMapper -> MyEntity)
Source:

lib/public/AppFramework/Db/Mapper.php#325

Parameters:
  • $row (array) the row which should be converted to an entity
Returns:

\OCP\AppFramework\Db\Entity the entity

Since:

7.0.0

Deprecated:

14.0.0 Move over to QBMapper

protected OCP\AppFramework\Db\Mapper::findEntities($sql, $params=[], $limit=null, $offset=null)
Runs a sql query and returns an array of entities
Source:

lib/public/AppFramework/Db/Mapper.php#340

Parameters:
  • $sql (string) the prepare string
  • $params (array) the params which should replace the ? in the sql query
  • $limit (int) the maximum number of rows
  • $offset (int) from which row we want to start
Returns:

array all fetched entities

Since:

7.0.0

Deprecated:

14.0.0 Move over to QBMapper

protected OCP\AppFramework\Db\Mapper::findEntity($sql, $params=[], $limit=null, $offset=null)
Returns an db result and throws exceptions when there are more or less
results
Source:

lib/public/AppFramework/Db/Mapper.php#368

Parameters:
  • $sql (string) the sql query
  • $params (array) the parameters of the sql query
  • $limit (int) the maximum number of rows
  • $offset (int) from which row we want to start
Throws:

\OCP\AppFramework\Db\DoesNotExistException if the item does not exist

Throws:

\OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one item exist

Throws:

\OCP\AppFramework\Db\DoesNotExistException if the item does not exist

Throws:

\OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one item exist

Returns:

\OCP\AppFramework\Db\Entity the entity

Since:

7.0.0

Deprecated:

14.0.0 Move over to QBMapper