PHP Class atk4\data\Persistence_SQL

Inheritance: extends Persistence
Datei anzeigen Open project: atk4/data Class Usage Examples

Public Properties

Property Type Description
$_default_class_addExpression string Default class when adding Expression field.
$_default_class_addField string Default class when adding new field.
$_default_class_hasMany string Default class when adding hasMany field.
$_default_class_hasOne string Default class when adding hasOne field.
$_default_class_join string Default class when adding join.
$connection atk4\dsql\Connection Connection object.

Public Methods

Method Description
__construct ( atk4\dsql\Connection | string $connection, string $user = null, string $password = null, array $args = [] ) Constructor.
_typecastLoadField ( Field $f, mixed $value ) : mixed This is the actual field typecasting, which you can override in your persistence to implement necessary typecasting.
_typecastSaveField ( Field $f, mixed $value ) : mixed This is the actual field typecasting, which you can override in your persistence to implement necessary typecasting.
action ( Model $m, string $type, array $args = [] ) : atk4\dsql\Query Executing $model->action('update') will call this method.
add ( Model | string $m, array $defaults = [] ) : Model Associate model with the data driver.
atomic ( callable $f ) : mixed Atomic executes operations within one begin/end transaction, so if the code inside callback will fail, then all of the transaction will be also rolled back.
delete ( Model $m, mixed $id ) Deletes record from database.
dsql ( ) : atk4\dsql\Query Returns Query instance.
export ( Model $m, array | null $fields = null ) : array Export all DataSet.
expr ( Model $m, string $expr, array $args = [] ) : atk4\dsql\Expression Creates new Expression object from expression.
initField ( atk4\dsql\Query $q, Field $field ) Adds Field in Query.
initQuery ( Model $m ) : atk4\dsql\Query Initializes base query for model $m.
initQueryConditions ( Model $m, atk4\dsql\Query $q ) : atk4\dsql\Query Will apply conditions defined inside $m onto query $q.
initQueryFields ( Model $m, atk4\dsql\Query $q, array | null $fields = null ) Adds model fields in Query.
insert ( Model $m, array $data ) : mixed Inserts record in database and returns new record ID.
load ( Model $m, mixed $id ) : array Loads a record from model and returns a associative array.
loadAny ( Model $m ) : array Loads any one record.
prepareIterator ( Model $m ) : PDOStatement Prepare iterator.
tryLoad ( Model $m, mixed $id ) : array Tries to load data record, but will not fail if record can't be loaded.
tryLoadAny ( Model $m ) : array Tries to load any one record.
update ( Model $m, mixed $id, array $data ) Updates record in database.

Protected Methods

Method Description
initPersistence ( Model $m ) Initialize persistence.
setLimitOrder ( Model $m, atk4\dsql\Query $q ) Will set limit defined inside $m onto query $q.

Method Details

__construct() public method

Constructor.
public __construct ( atk4\dsql\Connection | string $connection, string $user = null, string $password = null, array $args = [] )
$connection atk4\dsql\Connection | string
$user string
$password string
$args array

_typecastLoadField() public method

This is the actual field typecasting, which you can override in your persistence to implement necessary typecasting.
public _typecastLoadField ( Field $f, mixed $value ) : mixed
$f Field
$value mixed
return mixed

_typecastSaveField() public method

This is the actual field typecasting, which you can override in your persistence to implement necessary typecasting.
public _typecastSaveField ( Field $f, mixed $value ) : mixed
$f Field
$value mixed
return mixed

action() public method

Executing $model->action('update') will call this method.
public action ( Model $m, string $type, array $args = [] ) : atk4\dsql\Query
$m Model
$type string
$args array
return atk4\dsql\Query

add() public method

Associate model with the data driver.
public add ( Model | string $m, array $defaults = [] ) : Model
$m Model | string Model which will use this persistence
$defaults array Properties
return Model

atomic() public method

Atomic executes operations within one begin/end transaction, so if the code inside callback will fail, then all of the transaction will be also rolled back.
public atomic ( callable $f ) : mixed
$f callable
return mixed

delete() public method

Deletes record from database.
public delete ( Model $m, mixed $id )
$m Model
$id mixed

dsql() public method

Returns Query instance.
public dsql ( ) : atk4\dsql\Query
return atk4\dsql\Query

export() public method

Export all DataSet.
public export ( Model $m, array | null $fields = null ) : array
$m Model
$fields array | null
return array

expr() public method

Creates new Expression object from expression.
public expr ( Model $m, string $expr, array $args = [] ) : atk4\dsql\Expression
$m Model
$expr string
$args array
return atk4\dsql\Expression

initField() public method

Adds Field in Query.
public initField ( atk4\dsql\Query $q, Field $field )
$q atk4\dsql\Query
$field Field

initPersistence() protected method

Initialize persistence.
protected initPersistence ( Model $m )
$m Model

initQuery() public method

Initializes base query for model $m.
public initQuery ( Model $m ) : atk4\dsql\Query
$m Model
return atk4\dsql\Query

initQueryConditions() public method

Will apply conditions defined inside $m onto query $q.
public initQueryConditions ( Model $m, atk4\dsql\Query $q ) : atk4\dsql\Query
$m Model
$q atk4\dsql\Query
return atk4\dsql\Query

initQueryFields() public method

Adds model fields in Query.
public initQueryFields ( Model $m, atk4\dsql\Query $q, array | null $fields = null )
$m Model
$q atk4\dsql\Query
$fields array | null

insert() public method

Inserts record in database and returns new record ID.
public insert ( Model $m, array $data ) : mixed
$m Model
$data array
return mixed

load() public method

Loads a record from model and returns a associative array.
public load ( Model $m, mixed $id ) : array
$m Model
$id mixed
return array

loadAny() public method

Loads any one record.
public loadAny ( Model $m ) : array
$m Model
return array

prepareIterator() public method

Prepare iterator.
public prepareIterator ( Model $m ) : PDOStatement
$m Model
return PDOStatement

setLimitOrder() protected method

Will set limit defined inside $m onto query $q.
protected setLimitOrder ( Model $m, atk4\dsql\Query $q )
$m Model
$q atk4\dsql\Query

tryLoad() public method

Tries to load data record, but will not fail if record can't be loaded.
public tryLoad ( Model $m, mixed $id ) : array
$m Model
$id mixed
return array

tryLoadAny() public method

Tries to load any one record.
public tryLoadAny ( Model $m ) : array
$m Model
return array

update() public method

Updates record in database.
public update ( Model $m, mixed $id, array $data )
$m Model
$id mixed
$data array

Property Details

$_default_class_addExpression public_oe property

Default class when adding Expression field.
public string $_default_class_addExpression
return string

$_default_class_addField public_oe property

Default class when adding new field.
public string $_default_class_addField
return string

$_default_class_hasMany public_oe property

Default class when adding hasMany field.
public string $_default_class_hasMany
return string

$_default_class_hasOne public_oe property

Default class when adding hasOne field.
public string $_default_class_hasOne
return string

$_default_class_join public_oe property

Default class when adding join.
public string $_default_class_join
return string

$connection public_oe property

Connection object.
public Connection,atk4\dsql $connection
return atk4\dsql\Connection