Upgrade to 3.2.5
This commit is contained in:
@@ -21,7 +21,6 @@ use Throwable;
|
||||
*/
|
||||
class Database
|
||||
{
|
||||
|
||||
/**
|
||||
* The number of affected rows for the last query
|
||||
*
|
||||
@@ -180,7 +179,7 @@ class Database
|
||||
* Connects to a database
|
||||
*
|
||||
* @param array|null $params This can either be a config key or an array of parameters for the connection
|
||||
* @return Kirby\Database\Database
|
||||
* @return \Kirby\Database\Database
|
||||
*/
|
||||
public function connect(array $params = null)
|
||||
{
|
||||
@@ -223,7 +222,7 @@ class Database
|
||||
/**
|
||||
* Returns the currently active connection
|
||||
*
|
||||
* @return Kirby\Database\Database|null
|
||||
* @return \Kirby\Database\Database|null
|
||||
*/
|
||||
public function connection()
|
||||
{
|
||||
@@ -234,7 +233,7 @@ class Database
|
||||
* Sets the exception mode for the next query
|
||||
*
|
||||
* @param boolean $fail
|
||||
* @return Kirby\Database\Database
|
||||
* @return \Kirby\Database\Database
|
||||
*/
|
||||
public function fail(bool $fail = true)
|
||||
{
|
||||
@@ -467,7 +466,7 @@ class Database
|
||||
* Returns the correct Sql generator instance
|
||||
* for the type of database
|
||||
*
|
||||
* @return Kirby\Database\Sql
|
||||
* @return \Kirby\Database\Sql
|
||||
*/
|
||||
public function sql()
|
||||
{
|
||||
@@ -481,7 +480,7 @@ class Database
|
||||
* for that table
|
||||
*
|
||||
* @param string $table
|
||||
* @return Kirby\Database\Query
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function table(string $table)
|
||||
{
|
||||
@@ -579,6 +578,9 @@ class Database
|
||||
* Magic way to start queries for tables by
|
||||
* using a method named like the table.
|
||||
* I.e. $db->users()->all()
|
||||
*
|
||||
* @param mixed $method
|
||||
* @param mixed $arguments
|
||||
*/
|
||||
public function __call($method, $arguments = null)
|
||||
{
|
||||
|
@@ -36,7 +36,7 @@ class Db
|
||||
* (Re)connect the database
|
||||
*
|
||||
* @param array $params Pass [] to use the default params from the config
|
||||
* @return Kirby\Database\Database
|
||||
* @return \Kirby\Database\Database
|
||||
*/
|
||||
public static function connect(array $params = null)
|
||||
{
|
||||
@@ -61,7 +61,7 @@ class Db
|
||||
/**
|
||||
* Returns the current database connection
|
||||
*
|
||||
* @return Kirby\Database\Database
|
||||
* @return \Kirby\Database\Database
|
||||
*/
|
||||
public static function connection()
|
||||
{
|
||||
@@ -74,7 +74,7 @@ class Db
|
||||
* that table.
|
||||
*
|
||||
* @param string $table
|
||||
* @return Kirby\Database\Query
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public static function table($table)
|
||||
{
|
||||
@@ -177,12 +177,12 @@ Db::$queries['column'] = function (string $table, string $column, $where = null,
|
||||
};
|
||||
|
||||
/**
|
||||
* Shortcut for inserting a new row into a table
|
||||
*
|
||||
* @param string $table The name of the table, which should be queried
|
||||
* @param array $values An array of values, which should be inserted
|
||||
* @return boolean
|
||||
*/
|
||||
* Shortcut for inserting a new row into a table
|
||||
*
|
||||
* @param string $table The name of the table, which should be queried
|
||||
* @param array $values An array of values, which should be inserted
|
||||
* @return bool
|
||||
*/
|
||||
Db::$queries['insert'] = function (string $table, array $values) {
|
||||
return Db::table($table)->insert($values);
|
||||
};
|
||||
@@ -193,7 +193,7 @@ Db::$queries['insert'] = function (string $table, array $values) {
|
||||
* @param string $table The name of the table, which should be queried
|
||||
* @param array $values An array of values, which should be inserted
|
||||
* @param mixed $where An optional where clause
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
Db::$queries['update'] = function (string $table, array $values, $where = null) {
|
||||
return Db::table($table)->where($where)->update($values);
|
||||
@@ -204,7 +204,7 @@ Db::$queries['update'] = function (string $table, array $values, $where = null)
|
||||
*
|
||||
* @param string $table The name of the table, which should be queried
|
||||
* @param mixed $where An optional where clause
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
Db::$queries['delete'] = function (string $table, $where = null) {
|
||||
return Db::table($table)->where($where)->delete();
|
||||
|
@@ -150,7 +150,7 @@ class Query
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Kirby\Database\Database $database Database object
|
||||
* @param \Kirby\Database\Database $database Database object
|
||||
* @param string $table Optional name of the table, which should be queried
|
||||
*/
|
||||
public function __construct(Database $database, string $table)
|
||||
@@ -185,7 +185,7 @@ class Query
|
||||
* the query instead of actually executing the query and returning results
|
||||
*
|
||||
* @param boolean $debug
|
||||
* @return Kirby\Database\Query
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function debug(bool $debug = true)
|
||||
{
|
||||
@@ -197,7 +197,7 @@ class Query
|
||||
* Enables distinct select clauses.
|
||||
*
|
||||
* @param boolean $distinct
|
||||
* @return Kirby\Database\Query
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function distinct(bool $distinct = true)
|
||||
{
|
||||
@@ -210,7 +210,7 @@ class Query
|
||||
* If enabled queries will no longer fail silently but throw an exception
|
||||
*
|
||||
* @param boolean $fail
|
||||
* @return Kirby\Database\Query
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function fail(bool $fail = true)
|
||||
{
|
||||
@@ -223,7 +223,7 @@ class Query
|
||||
* Set this to array to get a simple array instead of an object
|
||||
*
|
||||
* @param string $fetch
|
||||
* @return Kirby\Database\Query
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function fetch(string $fetch)
|
||||
{
|
||||
@@ -236,7 +236,7 @@ class Query
|
||||
* Set this to array to get a simple array instead of an iterator object
|
||||
*
|
||||
* @param string $iterator
|
||||
* @return Kirby\Database\Query
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function iterator(string $iterator)
|
||||
{
|
||||
@@ -245,11 +245,11 @@ class Query
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the table, which should be queried
|
||||
*
|
||||
* @param string $table
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
* Sets the name of the table, which should be queried
|
||||
*
|
||||
* @param string $table
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function table(string $table)
|
||||
{
|
||||
if ($this->database->validateTable($table) === false) {
|
||||
@@ -264,7 +264,7 @@ class Query
|
||||
* Sets the name of the primary key column
|
||||
*
|
||||
* @param string $primaryKeyName
|
||||
* @return Kirby\Database\Query
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function primaryKeyName(string $primaryKeyName)
|
||||
{
|
||||
@@ -277,7 +277,7 @@ class Query
|
||||
* By default all columns will be selected
|
||||
*
|
||||
* @param mixed $select Pass either a string of columns or an array
|
||||
* @return Kirby\Database\Query
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function select($select)
|
||||
{
|
||||
@@ -310,7 +310,7 @@ class Query
|
||||
*
|
||||
* @param string $table Name of the table, which should be joined
|
||||
* @param string $on The on clause for this join
|
||||
* @return Kirby\Database\Query
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function leftJoin(string $table, string $on)
|
||||
{
|
||||
@@ -322,7 +322,7 @@ class Query
|
||||
*
|
||||
* @param string $table Name of the table, which should be joined
|
||||
* @param string $on The on clause for this join
|
||||
* @return Kirby\Database\Query
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function rightJoin(string $table, string $on)
|
||||
{
|
||||
@@ -334,7 +334,7 @@ class Query
|
||||
*
|
||||
* @param string $table Name of the table, which should be joined
|
||||
* @param string $on The on clause for this join
|
||||
* @return Kirby\Database\Query
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function innerJoin($table, $on)
|
||||
{
|
||||
@@ -345,7 +345,7 @@ class Query
|
||||
* Sets the values which should be used for the update or insert clause
|
||||
*
|
||||
* @param mixed $values Can either be a string or an array of values
|
||||
* @return Kirby\Database\Query
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function values($values = [])
|
||||
{
|
||||
@@ -383,8 +383,8 @@ class Query
|
||||
* ->where('username like ?', 'myuser') (args: 2)
|
||||
* ->where('username', 'like', 'myuser'); (args: 3)
|
||||
*
|
||||
* @param list
|
||||
* @return Kirby\Database\Query
|
||||
* @param mixed ...$args
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function where(...$args)
|
||||
{
|
||||
@@ -396,8 +396,8 @@ class Query
|
||||
* Shortcut to attach a where clause with an OR operator.
|
||||
* Check out the where() method docs for additional info.
|
||||
*
|
||||
* @param list
|
||||
* @return Kirby\Database\Query
|
||||
* @param mixed ...$args
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function orWhere(...$args)
|
||||
{
|
||||
@@ -420,8 +420,8 @@ class Query
|
||||
* Shortcut to attach a where clause with an AND operator.
|
||||
* Check out the where() method docs for additional info.
|
||||
*
|
||||
* @param list
|
||||
* @return Kirby\Database\Query
|
||||
* @param mixed ...$args
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function andWhere(...$args)
|
||||
{
|
||||
@@ -441,11 +441,11 @@ class Query
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches a group by clause
|
||||
*
|
||||
* @param string $group
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
* Attaches a group by clause
|
||||
*
|
||||
* @param string $group
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function group(string $group = null)
|
||||
{
|
||||
$this->group = $group;
|
||||
@@ -463,8 +463,8 @@ class Query
|
||||
* ->having('username like ?', 'myuser') (args: 2)
|
||||
* ->having('username', 'like', 'myuser'); (args: 3)
|
||||
*
|
||||
* @param list
|
||||
* @return Kirby\Database\Query
|
||||
* @param mixed ...$args
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function having(...$args)
|
||||
{
|
||||
@@ -476,7 +476,7 @@ class Query
|
||||
* Attaches an order clause
|
||||
*
|
||||
* @param string $order
|
||||
* @return Kirby\Database\Query
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function order(string $order = null)
|
||||
{
|
||||
@@ -488,7 +488,7 @@ class Query
|
||||
* Sets the offset for select clauses
|
||||
*
|
||||
* @param int $offset
|
||||
* @return Kirby\Database\Query
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function offset(int $offset = null)
|
||||
{
|
||||
@@ -500,7 +500,7 @@ class Query
|
||||
* Sets the limit for select clauses
|
||||
*
|
||||
* @param int $limit
|
||||
* @return Kirby\Database\Query
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function limit(int $limit = null)
|
||||
{
|
||||
@@ -559,7 +559,7 @@ class Query
|
||||
/**
|
||||
* Builds a count query
|
||||
*
|
||||
* @return Kirby\Database\Query
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
@@ -570,7 +570,7 @@ class Query
|
||||
* Builds a max query
|
||||
*
|
||||
* @param string $column
|
||||
* @return Kirby\Database\Query
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function max(string $column)
|
||||
{
|
||||
@@ -581,7 +581,7 @@ class Query
|
||||
* Builds a min query
|
||||
*
|
||||
* @param string $column
|
||||
* @return Kirby\Database\Query
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function min(string $column)
|
||||
{
|
||||
@@ -592,7 +592,7 @@ class Query
|
||||
* Builds a sum query
|
||||
*
|
||||
* @param string $column
|
||||
* @return Kirby\Database\Query
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function sum(string $column)
|
||||
{
|
||||
@@ -603,7 +603,7 @@ class Query
|
||||
* Builds an average query
|
||||
*
|
||||
* @param string $column
|
||||
* @return Kirby\Database\Query
|
||||
* @return \Kirby\Database\Query
|
||||
*/
|
||||
public function avg(string $column)
|
||||
{
|
||||
@@ -815,7 +815,7 @@ class Query
|
||||
$sql = $this->database->sql();
|
||||
$primaryKey = $sql->combineIdentifier($this->table, $this->primaryKeyName);
|
||||
|
||||
$results = $this->query($this->select(array($column))->order($primaryKey . ' ASC')->build('select'), [
|
||||
$results = $this->query($this->select([$column])->order($primaryKey . ' ASC')->build('select'), [
|
||||
'iterator' => 'array',
|
||||
'fetch' => 'array',
|
||||
]);
|
||||
|
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Kirby\Database;
|
||||
|
||||
use Closure;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Toolkit\A;
|
||||
use Kirby\Toolkit\Str;
|
||||
@@ -18,7 +17,6 @@ use Kirby\Toolkit\Str;
|
||||
*/
|
||||
class Sql
|
||||
{
|
||||
|
||||
/**
|
||||
* List of literals which should not be escaped in queries
|
||||
*
|
||||
@@ -36,7 +34,7 @@ class Sql
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Kirby\Database\Database $database
|
||||
* @param \Kirby\Database\Database $database
|
||||
*/
|
||||
public function __construct($database)
|
||||
{
|
||||
@@ -464,7 +462,7 @@ class Sql
|
||||
/**
|
||||
* Create the syntax for multiple joins
|
||||
*
|
||||
* @params array $joins
|
||||
* @param array $joins
|
||||
* @return array
|
||||
*/
|
||||
public function joins(array $joins = null): array
|
||||
@@ -677,11 +675,11 @@ class Sql
|
||||
switch (count($parts)) {
|
||||
// non-qualified identifier
|
||||
case 1:
|
||||
return array($table, $this->unquoteIdentifier($parts[0]));
|
||||
return [$table, $this->unquoteIdentifier($parts[0])];
|
||||
|
||||
// qualified identifier
|
||||
case 2:
|
||||
return array($this->unquoteIdentifier($parts[0]), $this->unquoteIdentifier($parts[1]));
|
||||
return [$this->unquoteIdentifier($parts[0]), $this->unquoteIdentifier($parts[1])];
|
||||
|
||||
// every other number is an error
|
||||
default:
|
||||
|
@@ -15,7 +15,6 @@ use Kirby\Database\Sql;
|
||||
*/
|
||||
class Sqlite extends Sql
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns a list of columns for a specified table
|
||||
* SQLite version
|
||||
|
Reference in New Issue
Block a user