bit-kitchen/zsql-multiplex

该包已被放弃,不再维护。未建议替代包。
此包的最新版本(v0.2.0)没有可用的许可信息。

v0.2.0 2016-08-19 22:58 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:52:41 UTC


README

Build Status

zsql\Database的替换方案,支持读写分离。

使用方法

$database = new \zsql\Multiplex($reader, $writer);

// select runs against $reader
$database->select()
  ->from('tableName')
  ->where('columnName', 'value')
  ->limit(1)
  ->query();

// insert runs against $writer
$id = $database->insert()
  ->ignore()
  ->into('tableName')
  ->value('columnName', 'value')
  ->value('otherColumnName', 'otherValue')
  ->query();

// update runs against $writer
$database->update()
  ->table('tableName')
  ->set('columnName', 'value')
  ->set('someColumn', new zsql\Expression('NOW()'))
  ->where('otherColumnName', 'otherValue')
  ->limit(1)
  ->query();

// delete runs against $writer
$database->delete()
  ->from('tableName')
  ->where('columnName', 'value')
  ->limit(1)
  ->query();

// ensure that the next query uses the $writer
$insert   = $database->query('SET @num := 1');
$result   = $database->useWriter()
  ->query('SELECT @num')
  ->fetchColumn();