Inheritance diagram for Record:Represents an "active record" table, derived from an annotated class implementing EntityInterface.
Class Annotations:
@record TABLEProperty Annotations:
@col or @column@unique or @unique <SHARED_IDENTIFIER> for a single or multi-column unique-key.@eav <TABLE>Property types are preserved. Properties which are objects can be dehydrated/rehydrated if they're strictly typed. Strict typing is preferred, but annotations and finally default values are used as fallbacks.
Annotating the types
String(capital "S") orSTRING(all caps) results inTEXTandBLOB
Protected Properties | |
| EAV[] | $eav = [] |
[property => EAV] More... | |
| EntityInterface | $proto |
| A boilerplate instance of the class, to clone and populate. More... | |
| Serializer | $serializer |
| const | EAV_BATCH_LOAD = 256 |
| The number of entities to load EAV entries for at a time, during Record::fetchEach() iteration. More... | |
Protected Properties inherited from Table | |
| Statement[] | $_cache = [] |
| Prepared statement cache, keyed by function name. More... | |
| Column[] | $columns = [] |
[name => Column] More... | |
| string | $name |
Protected Properties inherited from AbstractTable | |
| DB | $db |
Public Static Methods | |
| magic static self | factory (DB $db, string|EntityInterface $class) |
Public Static Methods inherited from Table | |
| magic static self | factory (DB $db, string $name, array $columns) |
Public Methods | |
| __construct (DB $db, $class) | |
| EntityInterface[] | fetchAll (Statement $statement) |
| Fetches from a statement into clones of the entity prototype. More... | |
| Generator EntityInterface[] | fetchEach (Statement $statement) |
| Fetches in chunks and yields each loaded entity. More... | |
| Select EntityInterface[] | findAll (array $match, array $eavMatch=[]) |
| Similar to loadAll() except this can additionally search by EAV values. More... | |
| null EntityInterface | findFirst (array $match, array $eavMatch=[]) |
| Returns an instance for the first row matching the criteria. More... | |
| string | getClass () |
| EAV[] | getEav () |
| EntityInterface | getProto () |
| Serializer | getSerializer () |
| null EntityInterface | load ($id) |
| Loads all data for a given ID (clones the prototype), or an existing instance. More... | |
| Select EntityInterface[] | loadAll () |
| Returns a Select that fetches instances. More... | |
| int | save (EntityInterface $entity) |
| Upserts record and EAV data. More... | |
| $this | setProto (EntityInterface $proto) |
Public Methods inherited from Table | |
| __construct (DB $db, string $name, array $columns) | |
| string | __toString () |
| Returns the table name. More... | |
| int | apply (array $values) |
INSERT IGNORE More... | |
| int | count (array $match=[]) |
| int | delete (array $match) |
| Executes a deletion using arbitrary columns. More... | |
| Column[] | getColumns () |
| string | getName () |
| Statement | insert (array $values) |
| Executes an insertion using arbitrary columns. More... | |
| Column | offsetGet ($column) |
| Select array[] | select ($expressions=[' *']) |
| Returns a selection object for columns or expressions in the table. More... | |
| Table | setName (string $name) |
| Returns an aliased clone for joins. More... | |
| int | update (array $values, array $match) |
| Executes an update using arbitrary columns. More... | |
Public Methods inherited from AbstractTable | |
| __construct (DB $db) | |
| bool | offsetExists ($column) |
| void | offsetSet ($offset, $value) |
| Throws. More... | |
| void | offsetUnset ($name) |
| Throws. More... | |
Protected Methods | |
| void | loadEav (array $entities) |
| Loads and sets all EAV properties for an array of entities keyed by ID. More... | |
| void | saveEav (EntityInterface $entity) |
| void | saveInsert (EntityInterface $entity) |
| Inserts a new row and updates the entity's ID. More... | |
| void | saveUpdate (EntityInterface $entity) |
| Updates the existing row for the entity. More... | |
Protected Methods inherited from Table | |
| Statement | cache (string $key, Closure $prepare) |
| Caches a prepared statement. More... | |
|
protected |
A boilerplate instance of the class, to clone and populate.
|
protected |
The number of entities to load EAV entries for at a time, during Record::fetchEach() iteration.
| __construct | ( | DB | $db, |
| $class | |||
| ) |
| DB | $db | |
| string | EntityInterface | $class |
|
static |
| EntityInterface [] fetchAll | ( | Statement | $statement | ) |
Fetches from a statement into clones of the entity prototype.
| Statement | $statement |
| Generator EntityInterface [] fetchEach | ( | Statement | $statement | ) |
Fetches in chunks and yields each loaded entity.
This is preferable over fetchAll() for iterating large result sets.
| Statement | $statement |
| Select EntityInterface [] findAll | ( | array | $match, |
| array | $eavMatch = [] |
||
| ) |
Similar to loadAll() except this can additionally search by EAV values.
| array | $match | [property => value] |
| array[] | $eavMatch | [eav property => attribute => value] |
| null EntityInterface findFirst | ( | array | $match, |
| array | $eavMatch = [] |
||
| ) |
Returns an instance for the first row matching the criteria.
| array | $match | [property => value] |
| array | $eavMatch | [eav property => attribute => value] |
|
final |
| EntityInterface getProto | ( | ) |
| Serializer getSerializer | ( | ) |
| null EntityInterface load | ( | $id | ) |
Loads all data for a given ID (clones the prototype), or an existing instance.
| int | EntityInterface | $id | The given instance may be a subclass of the prototype. |
| Select EntityInterface [] loadAll | ( | ) |
Returns a Select that fetches instances.
|
protected |
Loads and sets all EAV properties for an array of entities keyed by ID.
| EntityInterface[] | $entities | Keyed by ID |
| int save | ( | EntityInterface | $entity | ) |
|
protected |
| EntityInterface | $entity |
|
protected |
Inserts a new row and updates the entity's ID.
| EntityInterface | $entity |
|
protected |
Updates the existing row for the entity.
| EntityInterface | $entity |
| $this setProto | ( | EntityInterface | $proto | ) |
| EntityInterface | $proto |