DataSQL
in package
[$sql = $this->core->loadClass('DataSQL');] Class to Handle SQL databases with CloudFramework models
Table of Contents
Properties
- $core : Core7
- $dbConnections : mixed
- $dbCredentials : mixed
- $debug : mixed
- $default_time_zone_to_read : mixed
- $default_time_zone_to_write : mixed
- $entity_name : mixed
- $entity_schema : mixed
- $error : mixed
- $errorMsg : mixed
- $fields : mixed
- $keys : mixed
- $limit : mixed
- $mapping : mixed
- $offset : mixed
- $order : mixed
- $page : mixed
- $extraWhere : mixed
- $groupBy : mixed
- $joins : mixed
- $queryFields : mixed
- $queryWhere : mixed
- $use_mapping : mixed
- $view : mixed
- $virtualFields : mixed
Methods
- __construct() : mixed
- DataSQL constructor.
- addError() : mixed
- Add an error in the class
- addOrder() : mixed
- Add Order into a query with a new field
- addQueryWhere() : mixed
- Array with key=>value Especial values: '__null__' '__notnull__' '__empty__' '__notempty__'
- addVirtualField() : mixed
- delete() : bool|null|void
- Delete a record in db
- fetch() : array<string|int, mixed>|void
- Return records [0..n][record_structure] from the db object
- fetchByKeys() : mixed
- Return the tuplas with the $keyWhere including $fields
- fetchOne() : array<string|int, mixed>|void
- Return [record_structure]
- fetchOneByKey() : mixed
- Return one record based on a key
- getDBQuery() : string|null
- Return the last query executed
- getDBQueryTime() : int|null
- Return last time spent y last query
- getExtraWhere() : mixed
- getFields() : array<string|int, mixed>|null
- Return the fields defined for the table in the schema
- getFormModelWithMapData() : mixed|null
- Return the json form model to be used in validations in front-end
- getMappingFields() : array<string|int, mixed>
- Return the mapped field namesdefined in the schema mapping
- getQuerySQLFields() : mixed
- getQuerySQLFroms() : mixed
- getQuerySQLWhereAndParams() : array<string|int, mixed>|void
- Build a query taking $keysWhere and applying rules depending of each field type
- getSimpleModelFromTable() : mixed|null
- Return the json schema based on the table in the database
- getSQLSelectFields() : array<string|int, mixed>|null
- Return the fields ready for a SQL query
- getValidatedArrayFromData() : array<string|int, mixed>
- Return an array of the mapped fields ready to insert or update Validating the info
- getValidatedRecordToInsert() : mixed
- insert() : bool|null|void
- Update a record in db
- join() : mixed
- reset() : mixed
- Reset init values
- setExtraWhere() : mixed
- setGroupBy() : mixed
- setLimit() : mixed
- Set a limit in the select query or fetch method.
- setOffset() : mixed
- Set a offset in the select query or fetch method.
- setOrder() : mixed
- Set Order into a query with a field
- setPage() : mixed
- Set a page in the select query or fetch method.
- setQueryFields() : mixed
- Defines the fields to return in a query. If empty it will return all of them
- setQueryWhere() : mixed
- Array with key=>value Especial values: '__null__' '__notnull__' '__empty__' '__notempty__'
- setView() : mixed
- setVirtualField() : mixed
- unsetOrder() : mixed
- About Order
- update() : bool|null|void
- Update a record in db
- upsert() : bool|null|void
- Update a record in db
- useMapping() : mixed
- Active or deactive mapping of fields
- convertDateFieldsReadValuesIntoTimeZoneValues() : mixed
- Convert "now" values in ['date','datetime','timestamp'] into TimeZoneValue
- convertDateFieldsToWriteValuesIntoTimeZoneValues() : bool
- Convert "now" values in ['date','datetime','timestamp'] into TimeZoneValue before to update or insert
Properties
$core
public
Core7
$core
$dbConnections
public
mixed
$dbConnections
= []
$dbCredentials
public
mixed
$dbCredentials
= []
$debug
public
mixed
$debug
= \false
$default_time_zone_to_read
public
mixed
$default_time_zone_to_read
= 'UTC'
$default_time_zone_to_write
public
mixed
$default_time_zone_to_write
= 'UTC'
$entity_name
public
mixed
$entity_name
= \null
$entity_schema
public
mixed
$entity_schema
= \null
$error
public
mixed
$error
= \false
$errorMsg
public
mixed
$errorMsg
= ''
$fields
public
mixed
$fields
= []
$keys
public
mixed
$keys
= []
$limit
public
mixed
$limit
= 0
$mapping
public
mixed
$mapping
= []
$offset
public
mixed
$offset
= 0
$order
public
mixed
$order
= ''
$page
public
mixed
$page
= 0
$extraWhere
private
mixed
$extraWhere
= ''
$groupBy
private
mixed
$groupBy
= ''
$joins
private
mixed
$joins
= []
$queryFields
private
mixed
$queryFields
= ''
$queryWhere
private
mixed
$queryWhere
= []
$use_mapping
private
mixed
$use_mapping
= \false
$view
private
mixed
$view
= \null
$virtualFields
private
mixed
$virtualFields
= []
Methods
__construct()
DataSQL constructor.
public
__construct(Core7 &$core, array<string|int, mixed> $params) : mixed
Parameters
- $core : Core7
- $params : array<string|int, mixed>
-
where [0] is the table name and [1] is the model ['model'=>[],'mapping'=>[], etc..], 2 optionally is the connection name to have more than one connection
addError()
Add an error in the class
public
addError(mixed $value) : mixed
Parameters
- $value : mixed
addOrder()
Add Order into a query with a new field
public
addOrder( $field[, $type = 'ASC' ]) : mixed
Parameters
addQueryWhere()
Array with key=>value Especial values: '__null__' '__notnull__' '__empty__' '__notempty__'
public
addQueryWhere(array<string|int, mixed> $keysWhere) : mixed
Parameters
- $keysWhere : array<string|int, mixed>
addVirtualField()
public
addVirtualField( $field, $value) : mixed
Parameters
delete()
Delete a record in db
public
delete( $data) : bool|null|void
Parameters
Return values
bool|null|voidfetch()
Return records [0..n][record_structure] from the db object
public
fetch([array<string|int, mixed>|string $keysWhere = [] ][, null $fields = null ][, mixed $params = [] ]) : array<string|int, mixed>|void
Parameters
- $keysWhere : array<string|int, mixed>|string = []
-
where condition can be a string or array [key=>value, key=>value]
- $fields : null = null
-
fields to be returned
- $params : mixed = []
Return values
array<string|int, mixed>|voidfetchByKeys()
Return the tuplas with the $keyWhere including $fields
public
fetchByKeys( $keysWhere[, string $fields = '' ]) : mixed
Parameters
fetchOne()
Return [record_structure]
public
fetchOne([array<string|int, mixed> $keysWhere = [] ][, null $fields = null ][, mixed $params = [] ]) : array<string|int, mixed>|void
Parameters
- $keysWhere : array<string|int, mixed> = []
- $fields : null = null
- $params : mixed = []
Return values
array<string|int, mixed>|voidfetchOneByKey()
Return one record based on a key
public
fetchOneByKey( $key[, string $fields = '' ]) : mixed
Parameters
getDBQuery()
Return the last query executed
public
getDBQuery() : string|null
Return values
string|nullgetDBQueryTime()
Return last time spent y last query
public
getDBQueryTime() : int|null
Return values
int|nullgetExtraWhere()
public
getExtraWhere() : mixed
getFields()
Return the fields defined for the table in the schema
public
getFields() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|nullgetFormModelWithMapData()
Return the json form model to be used in validations in front-end
public
getFormModelWithMapData() : mixed|null
Return values
mixed|nullgetMappingFields()
Return the mapped field namesdefined in the schema mapping
public
getMappingFields() : array<string|int, mixed>
Return values
array<string|int, mixed>getQuerySQLFields()
public
getQuerySQLFields([mixed $fields = null ]) : mixed
Parameters
- $fields : mixed = null
getQuerySQLFroms()
public
getQuerySQLFroms() : mixed
getQuerySQLWhereAndParams()
Build a query taking $keysWhere and applying rules depending of each field type
public
getQuerySQLWhereAndParams([array<string|int, mixed> $keysWhere = [] ]) : array<string|int, mixed>|void
Parameters
- $keysWhere : array<string|int, mixed> = []
Return values
array<string|int, mixed>|voidgetSimpleModelFromTable()
Return the json schema based on the table in the database
public
getSimpleModelFromTable() : mixed|null
Return values
mixed|nullgetSQLSelectFields()
Return the fields ready for a SQL query
public
getSQLSelectFields([mixed $fields = null ]) : array<string|int, mixed>|null
Parameters
- $fields : mixed = null
Return values
array<string|int, mixed>|nullgetValidatedArrayFromData()
Return an array of the mapped fields ready to insert or update Validating the info
public
getValidatedArrayFromData( &$data[, mixed $all = true ][, array<string|int, mixed> &$dictionaries = [] ]) : array<string|int, mixed>
Parameters
Return values
array<string|int, mixed>getValidatedRecordToInsert()
public
getValidatedRecordToInsert(mixed &$data) : mixed
Parameters
- $data : mixed
insert()
Update a record in db
public
insert( $data) : bool|null|void
Parameters
Return values
bool|null|voidjoin()
public
join( $type, DataSQL &$object, $first_field, $join_field[, $extraon = null ]) : mixed
Parameters
- $type :
-
Could be inner or left
- $object : DataSQL
- $first_field :
-
string field of the local object to join with
- $join_field :
-
string field of the join object to match
- $extraon : = null
-
string any other extra condition
reset()
Reset init values
public
reset() : mixed
setExtraWhere()
public
setExtraWhere(mixed $extraWhere) : mixed
Parameters
- $extraWhere : mixed
setGroupBy()
public
setGroupBy( $group) : mixed
Parameters
setLimit()
Set a limit in the select query or fetch method.
public
setLimit(int $limit) : mixed
Parameters
- $limit : int
setOffset()
Set a offset in the select query or fetch method.
public
setOffset(int $offset) : mixed
Parameters
- $offset : int
setOrder()
Set Order into a query with a field
public
setOrder( $field[, $type = 'ASC' ]) : mixed
Parameters
setPage()
Set a page in the select query or fetch method.
public
setPage(int $page) : mixed
Parameters
- $page : int
setQueryFields()
Defines the fields to return in a query. If empty it will return all of them
public
setQueryFields( $fields) : mixed
Parameters
setQueryWhere()
Array with key=>value Especial values: '__null__' '__notnull__' '__empty__' '__notempty__'
public
setQueryWhere(array<string|int, mixed> $keysWhere) : mixed
Parameters
- $keysWhere : array<string|int, mixed>
setView()
public
setView(mixed $view) : mixed
Parameters
- $view : mixed
setVirtualField()
public
setVirtualField( $field, $value) : mixed
Parameters
unsetOrder()
About Order
public
unsetOrder() : mixed
update()
Update a record in db
public
update( &$data) : bool|null|void
Parameters
Return values
bool|null|voidupsert()
Update a record in db
public
upsert( $data) : bool|null|void
Parameters
Return values
bool|null|voiduseMapping()
Active or deactive mapping of fields
public
useMapping([bool $use = true ]) : mixed
Parameters
- $use : bool = true
convertDateFieldsReadValuesIntoTimeZoneValues()
Convert "now" values in ['date','datetime','timestamp'] into TimeZoneValue
private
convertDateFieldsReadValuesIntoTimeZoneValues( &$data) : mixed
Parameters
convertDateFieldsToWriteValuesIntoTimeZoneValues()
Convert "now" values in ['date','datetime','timestamp'] into TimeZoneValue before to update or insert
private
convertDateFieldsToWriteValuesIntoTimeZoneValues( &$data) : bool