Bluz\Db\Table

Table

Example of Users\Table
<code>
namespace Application\Users;
class Table extends \Bluz\Db\Table
{
protected $table = 'users';
protected $primary = ['id'];
}

$userRows = \Application\Users\Table::find(1,2,3,4,5);
foreach ($userRows as $userRow) {
$userRow -> description = 'In first 5';
$userRow -> save();
}
</code>

Synopsis

class Table {
}

Members

protected

  • $columns — array
  • $model — string
  • $name — string
  • $primary — array
  • $rowClass — string
  • $select — string
  • $sequence — string

Methods

private

public

  • create() — Create Row instance
  • delete() — Deletes existing rows
  • fetch() — Fetching rows by SQL query
  • fetchAll() — Fetch all rows from table Be carefully with this method, can be very slow
  • filterColumns() — Filter columns for insert/update queries by table columns definition
  • find() — Fetches rows by primary key. The argument specifies one or more primary key value(s). To find multiple rows by primary key, the argument must be an array.
  • findRow() — Find row by primary key
  • findRowWhere() — Find row by where condition
  • findWhere() — Find rows by WHERE // WHERE alias = 'foo' Table::findWhere(['alias'=>'foo']); // WHERE alias = 'foo' OR 'alias' = 'bar' Table::findWhere(['alias'=>'foo'], ['alias'=>'bar']); // WHERE (alias = 'foo' AND userId = 2) OR ('alias' = 'bar' AND userId = 4) Table::findWhere(['alias'=>'foo', 'userId'=> 2], ['alias'=>'foo', 'userId'=>4]); // WHERE alias IN ('foo', 'bar') Table::findWhere(['alias'=> ['foo', 'bar']]);
  • getColumns() — Return information about tables columns
  • getInstance() — Get Table instance
  • getModel() — Get model name
  • getName() — Get table name
  • getPrimaryKey() — Get primary key(s)
  • getSelectQuery() — Get select query
  • init() — Initialization hook.
  • insert() — Insert new record to table and return last insert Id
  • linkTo() — Setup relation "one to one" or "one to many"
  • linkToMany() — Setup relation "many to many" [table1-key] [table1_key-table2-table3_key] [table3-key]
  • select() — Prepare Db\Query\Select for current table: - predefine "select" section as "*" from current table - predefine "from" section as current table name and first letter as alias - predefine fetch type
  • setSelectQuery() — Set select query
  • update() — Updates existing rows

History