Свойство | Тип | Описание | |
---|---|---|---|
$connection | PD\PDO | Holds the current connection. |
Свойство | Тип | Описание | |
---|---|---|---|
$_cachedNames | array | Holds cached names. | |
$_classes | array | Classes used by Database. | |
$_columns | array | The supported column types and their default values | |
$_constraintTypes | |||
$_operators | array | List of SQL operators, paired with handling options. | |
$_quotes | array | A pair of opening/closing quote characters used for quoting identifiers in SQL queries. | |
$_strategies | array | Array of named callable objects representing different strategies for performing specific types of queries. | |
$_strings | array | Strings used to render the given statement |
Метод | Описание | |
---|---|---|
__construct ( array $config = [] ) : void | Constructor. | |
alias ( $alias, $context ) | ||
applyStrategy ( array $options, object $context ) | Applying a strategy to a lithium\data\model\Query object | |
calculation ( string $type, mixed $query, array $options = [] ) : integer | null | Executes calculation-related queries, such as those required for count and other aggregates. | |
cast ( $entity, array $data, array $options = [] ) | ||
column ( $field ) : string | Generate a database-native column schema string | |
comment ( string $comment ) : string | Adds formatting to SQL comments before they're embedded in queries. | |
conditions ( string | array $conditions, object $context, array $options = [] ) : string | Returns a string of formatted conditions to be inserted into the query statement. If the query conditions are defined as an array, key pairs are converted to SQL strings. | |
connect ( ) : boolean | Connects to the database by creating a PDO intance using the constructed DSN string. | |
constraints ( string | array $constraints, |
Returns a string of formatted constraints to be inserted into the query statement. | |
create ( object $query, array $options = [] ) : boolean | Inserts a new record into the database based on a the Query. The record is updated with the id of the insert. | |
createSchema ( string $source, object $schema ) : boolean | Create a database-native schema | |
delete ( object $query, array $options = [] ) : boolean | Deletes a record in the database based on the given Query. | |
disconnect ( ) : boolean | Disconnects the adapter from the database. | |
dropSchema ( string $source, boolean $soft = true ) : boolean | Drops a table. | |
encoding ( mixed $encoding = null ) : mixed. | Getter/Setter for the connection's encoding Abstract. Must be defined by child class. | |
error ( ) | Return the last errors produced by a the execution of a query. | |
fields ( array $fields, object $context ) : string | Returns a string of formatted fields to be inserted into the query statement. | |
group ( string | array $group, object $context ) : string | null | Return formatted clause for GROUP BY with known fields escaped. | |
having ( string | array $conditions, object $context, array $options = [] ) : string | Returns a string of formatted havings to be inserted into the query statement. If the query havings are defined as an array, key pairs are converted to SQL strings. | |
join ( object $context, object $rel, string $fromAlias = null, string $toAlias = null, mixed $constraints = [] ) | Set a query's join according a Relationship. | |
joins ( array $joins, |
Returns a join statement for given array of query objects | |
limit ( integer $limit, |
Returns a LIMIT statement from the given limit and the offset of the context object. | |
methods ( ) : array | Determines the set of methods to be used when exporting query values. | |
name ( string $name ) : string | Field name handler to ensure proper escaping. | |
on ( object $rel, $aliasFrom = null, $aliasTo = null, array $constraints = [] ) : array | Build the ON constraints from a Relationship instance | |
order ( string | array $order, object $context ) : string | null | Return formatted clause for ORDER BY with known fields escaped and directions normalized to uppercase. When order direction is missing or unrecognized defaults to ASC. | |
read ( string | object $query, array $options = [] ) : mixed | Reads records from a database using a lithium\data\model\Query object or raw SQL string. | |
relationship ( string $class, string $type, string $name, array $config = [] ) : array | Defines or modifies the default settings of a relationship between two models. | |
renderCommand ( string $type, string $data = null, string $context = null ) : string | Returns a given type statement for the given data, rendered from Database::$_strings. | |
schema ( |
Builds an array of keyed on the fully-namespaced Model with array of fields as values for the given Query | |
update ( object $query, array $options = [] ) : boolean | Updates a record in the database based on the given Query. | |
value ( mixed $value, array $schema = [] ) : mixed | Converts a given value into the proper type based on a given schema definition. |
Метод | Описание | |
---|---|---|
_aliasing ( string $name, string $alias, array $map = [] ) : string | Helper which add an alias basename to a field name if necessary | |
_buildConstraints ( array $constraints, type $schema = null, type $joiner = ' ', $primary = false ) : string | Helper for building columns constraints | |
_buildMetas ( $type, array $metas, array $names = null, type $joiner = ' ' ) : string | Helper for building columns metas | |
_cast ( string $type, string $value, array $column, array $schema = [] ) : mixed | Cast a value according to a column type, used by Database::value(). | |
_conditions ( string | array $conditions, object $context, array $options = [] ) : string | Returns a string of formatted conditions to be inserted into the query statement. | |
_constraint ( string $name, mixed $value, object $schema = null ) : string | Build a SQL column constraint | |
_constraints ( array $constraints ) : array | Auto escape string value to a field name value | |
_createFields ( array $data, array $schema, object $context ) : array | Renders the fields part for _create_ queries. | |
_entityName ( string $entity, array $options = [] ) : string | Returns a fully-qualified table name (i.e. with prefix), quoted. | |
_error ( string $sql ) | Throw a QueryException error | |
_execute ( string $sql ) : |
Execute a given query Abstract. Must be defined by child class. | |
_fieldName ( string $field ) : string | Return the field name from a conditions key. | |
_fields ( array $fields, object $context ) : array | Reformats fields to be alias based. | |
_fieldsQuote ( string $alias, string $field ) : string | Quotes fields, also handles aliased fields. | |
_fieldsReturn ( string $type, object $context, array $fields, array $schema ) : string | array | Renders the fields SQL fragment for queries. | |
_formatters ( ) : array | Provide an associative array of Closures to be used as the 'formatter' key inside of the Database::$_columns specification. Each Closure should return the appropriately quoted or unquoted value and accept one or two parameters: $format, the format to apply to value and $value, the value to be formatted. | |
_init ( ) | Initializer. Initializes properties like Database::$_strategies because closures cannot be created within the class definition. | |
_insertId ( $query ) : void | Get the last insert id from the database. | |
_introspectType ( mixed $value ) : string | Attempts to automatically determine the column type of a value. Used by the value() method of various database adapters to determine how to prepare a value if the schema is not specified. | |
_meta ( string $type, string $name, mixed $value ) : string | Build a SQL column/table meta. | |
_on ( array $constraints, $aliasFrom, $aliasTo, $mapAlias = [] ) | ||
_operator ( string $key, mixed $value, array $schema = [], array $options = [] ) : string | Handles conversion of SQL operator keys to SQL statements. | |
_processConditions ( $key, $value, $context, $schema = null, $glue = 'AND' ) | ||
_processOperator ( $key, $value, $fieldMeta, $glue ) : mixed | Helper method used by _processConditions. | |
_queryExport ( object $query ) : array | Helper method for Database::read() to export query while handling additional joins when using relationships and limited result sets. Filters conditions on subsequent queries to just the ones applying to the relation. | |
_schema ( |
Helper method for data\model\Database::shema() | |
_splitFieldname ( string $field ) : array | Return the alias and the field name from an identifier name. | |
_toBoolean ( mixed $value ) : boolean | Casts a value which is being written or compared to a boolean-type database column. | |
_updateFields ( array $data, array $schema, object $context ) : string | Renders the fields part for _update_ queries. |
public __construct ( array $config = [] ) : void | ||
$config | array | array Available configuration options are: - `'database'` _string_: Name of the database to use. Defaults to `null`. - `'host'` _string_: Name/address of server to connect to. Defaults to `'localhost'`. - `'login'` _string_: Username to use when connecting to server. Defaults to `'root'`. - `'password'` _string_: Password to use when connecting to server. Defaults to `''`. - `'persistent'` _boolean_: If true a persistent connection will be attempted, provided the adapter supports it. Defaults to `true`. |
Результат | void |
protected _buildConstraints ( array $constraints, type $schema = null, type $joiner = ' ', $primary = false ) : string | ||
$constraints | array | The array of constraints |
$schema | type | The schema of the table |
$joiner | type | The join character |
Результат | string | The SQL constraints |
protected _cast ( string $type, string $value, array $column, array $schema = [] ) : mixed | ||
$type | string | Name of the column type. |
$value | string | Value to cast. |
$column | array | The column definition. |
$schema | array | Formatted array from `lithium\data\source\Database::schema()`. |
Результат | mixed | Casted value. |
protected _conditions ( string | array $conditions, object $context, array $options = [] ) : string | ||
$conditions | string | array | The conditions for this query. |
$context | object | The current `lithium\data\model\Query` instance. |
$options | array | Available options are: - `'prepend'` _boolean|string_: The string to prepend or `false` for no prepending. Defaults to `false`. |
Результат | string | Returns an SQL conditions clause. |
protected _constraints ( array $constraints ) : array | ||
$constraints | array | The constraints array |
Результат | array | The escaped constraints array |
protected _createFields ( array $data, array $schema, object $context ) : array | ||
$data | array | |
$schema | array | An array defining the schema of the fields used in the criteria. |
$context | object | Generally a `data\model\Query` instance. |
Результат | array | Array with `fields` and `values` keys which hold SQL fragments of fields an values separated by comma. |
protected _fieldName ( string $field ) : string | ||
$field | string | Field or identifier name. |
Результат | string | Returns the field name without the table alias, if applicable. |
protected _fieldsReturn ( string $type, object $context, array $fields, array $schema ) : string | array | ||
$type | string | Type of query i.e. `'create'` or `'update'`. |
$context | object | Generally a `data\model\Query` instance. |
$fields | array | |
$schema | array | An array defining the schema of the fields used in the criteria. |
Результат | string | array |
protected _formatters ( ) : array | ||
Результат | array | of column types to Closure formatter |
protected _init ( ) |
protected _introspectType ( mixed $value ) : string | ||
$value | mixed | The value to be prepared for an SQL query. |
Результат | string | Returns the name of the column type which `$value` most likely belongs to. |
protected _operator ( string $key, mixed $value, array $schema = [], array $options = [] ) : string | ||
$key | string | Key in a conditions array. Usually a field name. |
$value | mixed | An SQL operator or comparison value. |
$schema | array | An array defining the schema of the field used in the criteria. |
$options | array | |
Результат | string | Returns an SQL string representing part of a `WHERE` clause of a query. |
protected _processConditions ( $key, $value, $context, $schema = null, $glue = 'AND' ) |
protected _processOperator ( $key, $value, $fieldMeta, $glue ) : mixed | ||
Результат | mixed | Returns the operator expression string or `false` if no operator is applicable. |
protected _queryExport ( object $query ) : array | ||
$query | object | The query object. |
Результат | array | The exported query returned by reference. |
protected _splitFieldname ( string $field ) : array | ||
$field | string | Field name or identifier name. |
Результат | array | Returns an array with the alias (or `null` if not applicable) as first value and the field name as second value. |
protected _toBoolean ( mixed $value ) : boolean | ||
$value | mixed | A value of unknown type to be cast to boolean. Numeric values not equal to zero evaluate to `true`, otherwise `false`. String values equal to `'true'`, `'t'` or `'T'` evaluate to `true`, all others to `false`. In all other cases, uses PHP's default casting. |
Результат | boolean | Returns a boolean representation of `$value`, based on the comparison rules specified above. Database adapters may override this method if boolean type coercion is required and falls outside the rules defined. |
public applyStrategy ( array $options, object $context ) | ||
$options | array | The option array |
$context | object | A find query object to configure |
public calculation ( string $type, mixed $query, array $options = [] ) : integer | null | ||
$type | string | Only accepts `count`. |
$query | mixed | The query to be executed. |
$options | array | Optional arguments for the `read()` query that will be executed to obtain the calculation result. |
Результат | integer | null | Result of the calculation or `null` if the calculation failed. |
public conditions ( string | array $conditions, object $context, array $options = [] ) : string | ||
$conditions | string | array | The conditions for this query. |
$context | object | The current `lithium\data\model\Query` instance. |
$options | array | Available options are: - `'prepend'` _boolean|string_: The string to prepend or `false` for no prepending. Defaults to `'WHERE'`. |
Результат | string | Returns the `WHERE` clause of an SQL query. |
public constraints ( string | array $constraints, |
||
$constraints | string | array | The constraints for a `ON` clause. |
$context | ||
$options | array | Available options are: - `'prepend'` _boolean|string_: The string to prepend or `false` for no prepending. Defaults to `'ON'`. |
Результат | string | Returns the `ON` clause of an SQL query. |
public create ( object $query, array $options = [] ) : boolean | ||
$query | object | An SQL query string, or `lithium\data\model\Query` object instance. |
$options | array | If $query is a string, $options contains an array of bind values to be escaped, quoted, and inserted into `$query` using `String::insert()`. |
Результат | boolean | Returns `true` if the query succeeded, otherwise `false`. |
public delete ( object $query, array $options = [] ) : boolean | ||
$query | object | An SQL string, or `lithium\data\model\Query` object instance. |
$options | array | If `$query` is a string, `$options` is the array of quoted/escaped parameter values to be inserted into the query. |
Результат | boolean | Returns `true` on successful query execution (not necessarily if records are deleted), otherwise `false`. |
public disconnect ( ) : boolean | ||
Результат | boolean | Returns `true` on success, else `false`. |
abstract public error ( ) |
public having ( string | array $conditions, object $context, array $options = [] ) : string | ||
$conditions | string | array | The havings for this query. |
$context | object | The current `lithium\data\model\Query` instance. |
$options | array | Available options are: - `'prepend'` _boolean|string_: The string to prepend or `false` for no prepending. Defaults to `'HAVING'`. |
Результат | string | Returns the `HAVING` clause of an SQL query. |
public join ( object $context, object $rel, string $fromAlias = null, string $toAlias = null, mixed $constraints = [] ) | ||
$context | object | A Query instance |
$rel | object | A Relationship instance |
$fromAlias | string | Set a specific alias for the `'from'` `Model`. |
$toAlias | string | Set a specific alias for `'to'` `Model`. |
$constraints | mixed | If `$constraints` is an array, it will be merged to defaults constraints. If `$constraints` is an object, defaults won't be merged. |
public read ( string | object $query, array $options = [] ) : mixed | ||
$query | string | object | `lithium\data\model\Query` object or SQL string. |
$options | array | If `$query` is a raw string, contains the values that will be escaped and quoted. Other options: - `'return'` _string_: switch return between `'array'`, `'item'`, or `'resource'` _string_: Defaults to `'item'`. |
Результат | mixed | Determined by `$options['return']`. |
public relationship ( string $class, string $type, string $name, array $config = [] ) : array | ||
$class | string | the primary model of the relationship |
$type | string | the type of the relationship (hasMany, hasOne, belongsTo) |
$name | string | the name of the relationship |
$config | array | relationship options |
Результат | array | Returns an array containing the configuration for a model relationship. |
protected array $_columns | ||
Результат | array |
protected array $_operators | ||
Результат | array |
protected array $_quotes | ||
Результат | array |
protected array $_strategies | ||
Результат | array |
protected array $_strings | ||
Результат | array |