mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-22 22:33:55 -07:00
Merge branch 'develop' of github.com:torrentpier/torrentpier into dl_new_database
This commit is contained in:
parent
0b23880a89
commit
c0580b0dc5
1 changed files with 40 additions and 2 deletions
|
@ -5,6 +5,7 @@ namespace TorrentPier\Db;
|
||||||
use TorrentPier\Config;
|
use TorrentPier\Config;
|
||||||
use Zend\Db\Adapter\Driver\ResultInterface;
|
use Zend\Db\Adapter\Driver\ResultInterface;
|
||||||
use Zend\Db\Adapter\Platform\PlatformInterface;
|
use Zend\Db\Adapter\Platform\PlatformInterface;
|
||||||
|
use Zend\Db\Adapter\Profiler\Profiler;
|
||||||
use Zend\Db\Adapter\Profiler\ProfilerInterface;
|
use Zend\Db\Adapter\Profiler\ProfilerInterface;
|
||||||
use Zend\Db\Exception\InvalidArgumentException;
|
use Zend\Db\Exception\InvalidArgumentException;
|
||||||
use Zend\Db\ResultSet\ResultSetInterface;
|
use Zend\Db\ResultSet\ResultSetInterface;
|
||||||
|
@ -35,6 +36,11 @@ class Adapter extends \Zend\Db\Adapter\Adapter
|
||||||
if ($driver instanceof Config) {
|
if ($driver instanceof Config) {
|
||||||
$driver = $driver->toArray();
|
$driver = $driver->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($profiler === null && is_array($driver) && !empty($driver['debug'])) {
|
||||||
|
$profiler = new Profiler();
|
||||||
|
}
|
||||||
|
|
||||||
parent::__construct($driver, $platform, $queryResultPrototype, $profiler);
|
parent::__construct($driver, $platform, $queryResultPrototype, $profiler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +78,6 @@ class Adapter extends \Zend\Db\Adapter\Adapter
|
||||||
* @param $table
|
* @param $table
|
||||||
* @param array $values
|
* @param array $values
|
||||||
* @return mixed|null
|
* @return mixed|null
|
||||||
*
|
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function insert($table, array $values)
|
public function insert($table, array $values)
|
||||||
|
@ -98,7 +103,6 @@ class Adapter extends \Zend\Db\Adapter\Adapter
|
||||||
* @param array $values
|
* @param array $values
|
||||||
* @param Where|\Closure|string|array $where
|
* @param Where|\Closure|string|array $where
|
||||||
* @return int
|
* @return int
|
||||||
*
|
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function update($table, array $values, $where)
|
public function update($table, array $values, $where)
|
||||||
|
@ -194,4 +198,38 @@ class Adapter extends \Zend\Db\Adapter\Adapter
|
||||||
$result = $statementContainer->execute();
|
$result = $statementContainer->execute();
|
||||||
return $result->current()['count'];
|
return $result->current()['count'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increment field by query.
|
||||||
|
*
|
||||||
|
* @param string $table
|
||||||
|
* @param string $field
|
||||||
|
* @param Where|\Closure|string|array $where
|
||||||
|
* @param int $num
|
||||||
|
* @return int
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function increment($table, $field, $where = null, $num = 1)
|
||||||
|
{
|
||||||
|
return $this->update($table, [
|
||||||
|
$field => new Expression('? + ?', [$field, $num], [Expression::TYPE_IDENTIFIER, Expression::TYPE_VALUE])
|
||||||
|
], $where);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrement field by query.
|
||||||
|
*
|
||||||
|
* @param string $table
|
||||||
|
* @param string $field
|
||||||
|
* @param Where|\Closure|string|array $where
|
||||||
|
* @param int $num
|
||||||
|
* @return int
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function decrement($table, $field, $where = null, $num = 1)
|
||||||
|
{
|
||||||
|
return $this->update($table, [
|
||||||
|
$field => new Expression('? - ?', [$field, $num], [Expression::TYPE_IDENTIFIER, Expression::TYPE_VALUE])
|
||||||
|
], $where);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue