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>
- Author: Anton Shevchuk
Synopsis
- // members
- protected $name;
- protected $model;
- protected array $meta = ;
- protected string $select = '';
- protected $primary;
- protected $sequence;
- protected $rowClass;
- // methods
- private void __construct()
- public void init()
- public static Table getInstance()
- public Table setSelectQuery()
- public string getSelectQuery()
- public array getPrimaryKey()
- public string getName()
- public string getModel()
- public static array getMeta()
- public static array getColumns()
- public static array filterColumns()
- public static array fetch()
- public static array fetchAll()
- public static array find()
- public static Row findRow()
- public static array findWhere()
- public static Row findRowWhere()
- private static array prepareStatement()
- public static Select select()
- public static Row create()
- public static string|null insert()
- public static integer update()
- public static integer delete()
- public void linkTo()
- public void linkToMany()
Members
protected
- $meta — array
- $model — string
- $name — string
- $primary — array
- $rowClass — string
- $select — string
- $sequence — string
Methods
private
- __construct() — Create and initialize Table instance
- prepareStatement() — Prepare array for WHERE or SET statements
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 names of table columns
- getInstance() — Get Table instance
- getMeta() — Return information about table columns
- 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
-
2017-11-07T12:29:29+00:00 (commit #2c5c5ce)
Author: Anton Shevchuk (AntonShevchuk@gmail.com) / Commiter: Anton Shevchuk (AntonShevchuk@gmail.com)
Added method `Db::fetchUniqueGroup()` Added method `Table::getMeta()` Updated codestyle of tests
-
2017-10-11T15:57:50+00:00 (commit #812be85)
Author: Anton Shevchuk (AntonShevchuk@gmail.com) / Commiter: Anton Shevchuk (AntonShevchuk@gmail.com)
Made `Table::getColimns` static
-
2017-08-03T14:39:04+00:00 (commit #0b47390)
Author: Anton Shevchuk (AntonShevchuk@gmail.com) / Commiter: Anton Shevchuk (AntonShevchuk@gmail.com)
Removed unused code
-
2017-08-03T14:11:40+00:00 (commit #15278f6)
Author: Anton Shevchuk (AntonShevchuk@gmail.com) / Commiter: Anton Shevchuk (AntonShevchuk@gmail.com)
Renamed `Line` to `Str` Added `class_namespace` function
-
2017-06-30T08:36:40+00:00 (commit #2259ecf)
Author: Anton Shevchuk (AntonShevchuk@gmail.com) / Commiter: Anton Shevchuk (AntonShevchuk@gmail.com)
Fixed comments style
-
2017-04-26T12:53:22+00:00 (commit #ff59da1)
Author: Anton Shevchuk (AntonShevchuk@gmail.com) / Commiter: Anton Shevchuk (AntonShevchuk@gmail.com)
Added `Common\Line` class Added `to_camel_case` function Added `str_trim_end` function
-
2017-04-21T15:28:30+00:00 (commit #f0410e7)
Author: Anton Shevchuk (AntonShevchuk@gmail.com) / Commiter: Anton Shevchuk (AntonShevchuk@gmail.com)
Replace `join` with `implode`
-
2017-04-21T15:14:44+00:00 (commit #c7538da)
Author: Anton Shevchuk (AntonShevchuk@gmail.com) / Commiter: Anton Shevchuk (AntonShevchuk@gmail.com)
Replace `sizeof` to `count`
-
2017-04-21T13:24:35+00:00 (commit #3b25a3d)
Author: Anton Shevchuk (AntonShevchuk@gmail.com) / Commiter: Anton Shevchuk (AntonShevchuk@gmail.com)
Small update for codestyle
-
2017-04-12T09:45:17+00:00 (commit #e8463fb)
Author: Anton Shevchuk (AntonShevchuk@gmail.com) / Commiter: Anton Shevchuk (AntonShevchuk@gmail.com)
Fixed controller cache issue
-
2017-02-15T16:09:44+00:00 (commit #0fc0c8b)
Author: Anton Shevchuk (AntonShevchuk@gmail.com) / Commiter: Anton Shevchuk (AntonShevchuk@gmail.com)
Updated coveralls config
-
2017-02-13T10:14:18+00:00 (commit #43dbf55)
Author: Anton Shevchuk (AntonShevchuk@gmail.com) / Commiter: Anton Shevchuk (AntonShevchuk@gmail.com)
Rollback to `getCount()` method
-
2017-01-30T13:15:49+00:00 (commit #fd5d943)
Author: Anton (AntonShevchuk@gmail.com) / Commiter: GitHub (AntonShevchuk@gmail.com)
Merge pull request #395 from AntonShevchuk/master Added `AttachmentResponse`
-
2017-01-30T12:38:53+00:00 (commit #0ab8691)
Author: Anton Shevchuk (AntonShevchuk@gmail.com) / Commiter: Anton Shevchuk (AntonShevchuk@gmail.com)
Added `AttachmentResponse` Added `attachment($file)` helper for `Controller`