com\setasign\SetaFramework\Database\Table

Table Class Table

File: /SetaFramework/src/Database/Table/Table.php

Class hierarchy

Implements

Summary

Constants

OPTION_COLUMNS

public const Table::OPTION_COLUMNS = 'columns'

OPTION_MAGIC_COLUMNS

public const Table::OPTION_MAGIC_COLUMNS = 'magicColumns'

OPTION_METADATA_CACHE

public const Table::OPTION_METADATA_CACHE = 'metadataCache'

OPTION_PRIMARY_KEY

public const Table::OPTION_PRIMARY_KEY = 'primaryKey'

OPTION_ROW_CLASS_NAME

public const Table::OPTION_ROW_CLASS_NAME = 'rowClassName'

OPTION_TABLE_NAME

public const Table::OPTION_TABLE_NAME = 'tableName'

Properties

$columns

protected array Table::$columns

Available columns

$db

$hiddenColumns

protected array Table::$hiddenColumns = array()

Columns which will not get exposed through the toArray() method of a table row

$magicColumns

protected array Table::$magicColumns

Available magic columns

$metadataCache

protected ?\Psr\SimpleCache\CacheInterface Table::$metadataCache

A cache object for storing table metadata

$primaryKey

protected array<string, string> Table::$primaryKey

Contains the primary key ['columnA' => 'tableA.columnA', 'columnB' => 'tableA.columnB']

$rowClassName

protected string Table::$rowClassName

The row class name

$tableName

protected string Table::$tableName

The table name


Methods

__construct()

The constructor

Available Options:

OptionTypeDescriptionSampleData
tableName* array Contains all tableNames of the tables ['tableA', 'tableB']
rowClassName string Classname for the row objects of this table. Row
columns array Contains all columns of the table ['columnA', 'columnB']
primaryKey array Contains the primary key; This shouldn't be wrong or incomplete. ['columnA' => 'tableA.columnA', 'columnB' => 'tableA.columnB']
metadataCache\Psr\SimpleCache\CacheInterface Cache-object for metadata-
magicColumns array Contains special columns that are read only and can use Expression. ['Name' => new Expression('concat(`firstname`, ' ', `lastname`))]

*required

Parameters
$db : \com\setasign\SetaFramework\Database\Database
 
$rowFactory : \com\setasign\SetaFramework\Database\RowFactoryInterface
 
$options : ?array
 
Exceptions

Throws MissingPrimaryKeyException If a table doesn't have a primary key

__sleep()

public Table::__sleep (
void
): void

createRow()

public Table::createRow (
array $data = array ( )
): Row
Parameters
$data : array
 

delete()

public Table::delete (
string|callable $where
): void

Delete from the database table

Parameters
$where : string|callable
 

find()

public Table::find (
int|string|array<string, mixed> $primaryKey,
?Row $row = null
): ?Row

Returns a Table\Row object.

Parameters
$primaryKey : int|string|array<string, mixed>
 
$row : ?Row

If this is set and the primary key is set, the result data will put into this object.

Exceptions

Throws \InvalidArgumentException If one or more primary keys are missing

getColumns()

public Table::getColumns (
void
): array

Get all column names

getDb()

Returns the datanase instance

getHiddenColumns()

public Table::getHiddenColumns (
void
): array

Get all hidden columns

getMagicColumns()

public Table::getMagicColumns (
void
): array

Get all magic columns

getPrimaryKey()

public Table::getPrimaryKey (
void
): array

Get the primary key columns

getRowClassName()

public Table::getRowClassName (
void
): string

Get the row class name

getSelect()

Get a prepared select query for this table

getTableName()

public Table::getTableName (
void
): string

Get the table name

insert()

public Table::insert (
array $data
): int

Insert a row into the table.

Parameters
$data : array
 
Return Values

Returns the last inserted id

insertMultiple()

public Table::insertMultiple (
array $datas
): void

Insert multiple rows into the table.

Parameters
$datas : array

All rows need the same columns!!

update()

public Table::update (
array $data,
null|string|callable $where = null
): void

Updates one or more rows in the table.

Parameters
$data : array
 
$where : null|string|callable