Upgrade to 3.2.0
This commit is contained in:
@@ -12,6 +12,12 @@ use Throwable;
|
||||
|
||||
/**
|
||||
* A simple database class
|
||||
*
|
||||
* @package Kirby Database
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Database
|
||||
{
|
||||
@@ -153,9 +159,9 @@ class Database
|
||||
* Returns one of the started instance
|
||||
*
|
||||
* @param string $id
|
||||
* @return Database
|
||||
* @return self
|
||||
*/
|
||||
public static function instance(string $id = null): self
|
||||
public static function instance(string $id = null)
|
||||
{
|
||||
return $id === null ? A::last(static::$connections) : static::$connections[$id] ?? null;
|
||||
}
|
||||
@@ -174,7 +180,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 Database
|
||||
* @return Kirby\Database\Database
|
||||
*/
|
||||
public function connect(array $params = null)
|
||||
{
|
||||
@@ -217,7 +223,7 @@ class Database
|
||||
/**
|
||||
* Returns the currently active connection
|
||||
*
|
||||
* @return Database|null
|
||||
* @return Kirby\Database\Database|null
|
||||
*/
|
||||
public function connection()
|
||||
{
|
||||
@@ -228,7 +234,7 @@ class Database
|
||||
* Sets the exception mode for the next query
|
||||
*
|
||||
* @param boolean $fail
|
||||
* @return Database
|
||||
* @return Kirby\Database\Database
|
||||
*/
|
||||
public function fail(bool $fail = true)
|
||||
{
|
||||
@@ -461,7 +467,7 @@ class Database
|
||||
* Returns the correct Sql generator instance
|
||||
* for the type of database
|
||||
*
|
||||
* @return Sql
|
||||
* @return Kirby\Database\Sql
|
||||
*/
|
||||
public function sql()
|
||||
{
|
||||
@@ -470,10 +476,12 @@ class Database
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current table, which should be queried
|
||||
* Sets the current table, which should be queried. Returns a
|
||||
* Query object, which can be used to build a full query
|
||||
* for that table
|
||||
*
|
||||
* @param string $table
|
||||
* @return Query Returns a Query object, which can be used to build a full query for that table
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function table(string $table)
|
||||
{
|
||||
|
@@ -7,6 +7,12 @@ use Kirby\Toolkit\Config;
|
||||
|
||||
/**
|
||||
* Database shortcuts
|
||||
*
|
||||
* @package Kirby Database
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Db
|
||||
{
|
||||
@@ -30,7 +36,7 @@ class Db
|
||||
* (Re)connect the database
|
||||
*
|
||||
* @param array $params Pass [] to use the default params from the config
|
||||
* @return Database
|
||||
* @return Kirby\Database\Database
|
||||
*/
|
||||
public static function connect(array $params = null)
|
||||
{
|
||||
@@ -55,7 +61,7 @@ class Db
|
||||
/**
|
||||
* Returns the current database connection
|
||||
*
|
||||
* @return Database
|
||||
* @return Kirby\Database\Database
|
||||
*/
|
||||
public static function connection()
|
||||
{
|
||||
@@ -63,10 +69,12 @@ class Db
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current table, which should be queried
|
||||
* Sets the current table, which should be queried. Returns a
|
||||
* Query object, which can be used to build a full query for
|
||||
* that table.
|
||||
*
|
||||
* @param string $table
|
||||
* @return Query Returns a Query object, which can be used to build a full query for that table
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public static function table($table)
|
||||
{
|
||||
|
@@ -10,6 +10,12 @@ use Kirby\Toolkit\Str;
|
||||
/**
|
||||
* The query builder is used by the Database class
|
||||
* to build SQL queries with a fluent API
|
||||
*
|
||||
* @package Kirby Database
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Query
|
||||
{
|
||||
@@ -144,7 +150,7 @@ class Query
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param 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)
|
||||
@@ -179,7 +185,7 @@ class Query
|
||||
* the query instead of actually executing the query and returning results
|
||||
*
|
||||
* @param boolean $debug
|
||||
* @return Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function debug(bool $debug = true)
|
||||
{
|
||||
@@ -191,7 +197,7 @@ class Query
|
||||
* Enables distinct select clauses.
|
||||
*
|
||||
* @param boolean $distinct
|
||||
* @return Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function distinct(bool $distinct = true)
|
||||
{
|
||||
@@ -204,7 +210,7 @@ class Query
|
||||
* If enabled queries will no longer fail silently but throw an exception
|
||||
*
|
||||
* @param boolean $fail
|
||||
* @return Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function fail(bool $fail = true)
|
||||
{
|
||||
@@ -217,7 +223,7 @@ class Query
|
||||
* Set this to array to get a simple array instead of an object
|
||||
*
|
||||
* @param string $fetch
|
||||
* @return Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function fetch(string $fetch)
|
||||
{
|
||||
@@ -230,7 +236,7 @@ class Query
|
||||
* Set this to array to get a simple array instead of an iterator object
|
||||
*
|
||||
* @param string $iterator
|
||||
* @return Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function iterator(string $iterator)
|
||||
{
|
||||
@@ -242,7 +248,7 @@ class Query
|
||||
* Sets the name of the table, which should be queried
|
||||
*
|
||||
* @param string $table
|
||||
* @return Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function table(string $table)
|
||||
{
|
||||
@@ -258,7 +264,7 @@ class Query
|
||||
* Sets the name of the primary key column
|
||||
*
|
||||
* @param string $primaryKeyName
|
||||
* @return Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function primaryKeyName(string $primaryKeyName)
|
||||
{
|
||||
@@ -271,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 Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function select($select)
|
||||
{
|
||||
@@ -304,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 Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function leftJoin(string $table, string $on)
|
||||
{
|
||||
@@ -316,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 Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function rightJoin(string $table, string $on)
|
||||
{
|
||||
@@ -328,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 Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function innerJoin($table, $on)
|
||||
{
|
||||
@@ -339,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 Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function values($values = [])
|
||||
{
|
||||
@@ -378,7 +384,7 @@ class Query
|
||||
* ->where('username', 'like', 'myuser'); (args: 3)
|
||||
*
|
||||
* @param list
|
||||
* @return Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function where(...$args)
|
||||
{
|
||||
@@ -391,7 +397,7 @@ class Query
|
||||
* Check out the where() method docs for additional info.
|
||||
*
|
||||
* @param list
|
||||
* @return Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function orWhere(...$args)
|
||||
{
|
||||
@@ -415,7 +421,7 @@ class Query
|
||||
* Check out the where() method docs for additional info.
|
||||
*
|
||||
* @param list
|
||||
* @return Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function andWhere(...$args)
|
||||
{
|
||||
@@ -438,7 +444,7 @@ class Query
|
||||
* Attaches a group by clause
|
||||
*
|
||||
* @param string $group
|
||||
* @return Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function group(string $group = null)
|
||||
{
|
||||
@@ -458,7 +464,7 @@ class Query
|
||||
* ->having('username', 'like', 'myuser'); (args: 3)
|
||||
*
|
||||
* @param list
|
||||
* @return Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function having(...$args)
|
||||
{
|
||||
@@ -470,7 +476,7 @@ class Query
|
||||
* Attaches an order clause
|
||||
*
|
||||
* @param string $order
|
||||
* @return Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function order(string $order = null)
|
||||
{
|
||||
@@ -482,7 +488,7 @@ class Query
|
||||
* Sets the offset for select clauses
|
||||
*
|
||||
* @param int $offset
|
||||
* @return Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function offset(int $offset = null)
|
||||
{
|
||||
@@ -494,7 +500,7 @@ class Query
|
||||
* Sets the limit for select clauses
|
||||
*
|
||||
* @param int $limit
|
||||
* @return Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function limit(int $limit = null)
|
||||
{
|
||||
@@ -553,7 +559,7 @@ class Query
|
||||
/**
|
||||
* Builds a count query
|
||||
*
|
||||
* @return Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
@@ -564,7 +570,7 @@ class Query
|
||||
* Builds a max query
|
||||
*
|
||||
* @param string $column
|
||||
* @return Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function max(string $column)
|
||||
{
|
||||
@@ -575,7 +581,7 @@ class Query
|
||||
* Builds a min query
|
||||
*
|
||||
* @param string $column
|
||||
* @return Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function min(string $column)
|
||||
{
|
||||
@@ -586,7 +592,7 @@ class Query
|
||||
* Builds a sum query
|
||||
*
|
||||
* @param string $column
|
||||
* @return Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function sum(string $column)
|
||||
{
|
||||
@@ -597,7 +603,7 @@ class Query
|
||||
* Builds an average query
|
||||
*
|
||||
* @param string $column
|
||||
* @return Query
|
||||
* @return Kirby\Database\Query
|
||||
*/
|
||||
public function avg(string $column)
|
||||
{
|
||||
|
@@ -9,6 +9,12 @@ use Kirby\Toolkit\Str;
|
||||
|
||||
/**
|
||||
* SQL Query builder
|
||||
*
|
||||
* @package Kirby Database
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Sql
|
||||
{
|
||||
@@ -30,7 +36,7 @@ class Sql
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Database $database
|
||||
* @param Kirby\Database\Database $database
|
||||
*/
|
||||
public function __construct($database)
|
||||
{
|
||||
|
@@ -6,6 +6,12 @@ use Kirby\Database\Sql;
|
||||
|
||||
/**
|
||||
* Mysql query builder
|
||||
*
|
||||
* @package Kirby Database
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Mysql extends Sql
|
||||
{
|
||||
|
@@ -6,6 +6,12 @@ use Kirby\Database\Sql;
|
||||
|
||||
/**
|
||||
* Sqlite query builder
|
||||
*
|
||||
* @package Kirby Database
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Sqlite extends Sql
|
||||
{
|
||||
|
Reference in New Issue
Block a user