DataBQ
in package
[$bq = $this->core->loadClass('DataBQ');] Class to handle Bigquery datasets:tables with CloudFramework models
https://cloud.google.com/bigquery/docs/reference/libraries#client-libraries-install-php
Table of Contents
Properties
- $_last_query : mixed
- $_last_query_time : mixed
- $_lastExecutionMicrotime : mixed
- $_only_create_query : mixed
- $_version : mixed
- $client : BigQueryClient|null
- $core : mixed
- $dataset : Dataset
- $dataset_name : mixed
- $debug : mixed
- $entity_schema : mixed
- $error : mixed
- $errorCode : mixed
- $errorMsg : mixed
- $fields : mixed
- $key : mixed
- $limit : mixed
- $mapping : mixed
- $offset : mixed
- $options : mixed
- $order : mixed
- $page : mixed
- $project_id : mixed
- $table : Table
- $table_name : mixed
- $extraWhere : mixed
- $groupBy : mixed
- $joins : mixed
- $queryFields : mixed
- $queryWhere : mixed
- $use_mapping : mixed
- $view : mixed
- $virtualFields : mixed
Methods
- __construct() : mixed
- _insertWithStreamingBuffer() : bool|null|void
- Insert a record in dataset.table
- addError() : bool
- Adds an error message to the list of error messages.
- 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
- checkBigQueryStructure() : array<string|int, mixed>
- Return a structure with bigquery squema based on CF model
- createDataSetTableInfo() : array<string|int, mixed>
- Creates a table in the given dataset with the specified fields.
- dbFeed() : array<string|int, mixed>|void
- Feed a table in Bigquery
- dbQuery() : array<string|int, mixed>|void
- Execute a Query with a title
- 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
- getBigQueryStructureFromModel() : array<string|int, mixed>
- Return a structure with bigquery squema based on CF model
- getDataSetInfo() : array<string|int, mixed>|false
- Return information about the specified dataset.
- getDataSets() : array<string|int, mixed>|false
- Return datasets associated to the project
- getDataSetTableInfo() : array<string|int, mixed>|false
- Retrieves information about the specified table in the given dataset or the default dataset.
- getDataSetTables() : array<string|int, mixed>|false
- Retrieves the tables in the given dataset or the default dataset.
- getDBQuery() : null|string
- Return 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
- getInterfaceModelFromDatasetTable() : array<string|int, mixed>
- Return a structure with bigquery squema based on CF model
- getMappingFields() : array<string|int, mixed>
- Return the mapped field namesdefined in the schema mapping
- getQuerySQLFields() : mixed
- getQuerySQLFroms() : mixed
- getQuerySQLWhereAndParams() : mixed
- 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
- Insert a record in db. If $upsert is true and the record exist then update it
- insertWithStreamingBuffer() : array<string|int, mixed>|false
- Inserts data with streaming buffer into the BigQuery table.
- join() : mixed
- onlyCreateQuery() : mixed
- Define When I want to build a query but I do not want to be executed I call this method with true value
- query() : 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
- softDelete() : bool|null|void
- Update a record in db It requires to add always the following condition: and _created < TIMESTAMP_SUB(_created, INTERVAL 30 MINUTE) because you can not update or delete records inserted before 30' has passed
- test() : array<string|int, mixed>|void
- Just a test query to know if the service works
- unsetOrder() : mixed
- About Order
- update() : bool|null|void
- Update a record in db It requires to add always the following condition: and _created < TIMESTAMP_SUB(_created, INTERVAL 30 MINUTE) because you can not update or delete records inserted before 30' has passed
- upsert() : bool|null|void
- Upsert a record in db
- useMapping() : mixed
- Active or deactive mapping of fields
- _feed() : bool
- Feeds data into the specified BigQuery table.
- _query() : array<string|int, mixed>|false
- Executes a query with optional parameters.
- processSchema() : bool|void
- Process Schema
Properties
$_last_query
public
mixed
$_last_query
= \null
$_last_query_time
public
mixed
$_last_query_time
= 0
$_lastExecutionMicrotime
public
mixed
$_lastExecutionMicrotime
= 0
$_only_create_query
public
mixed
$_only_create_query
= \false
$_version
public
mixed
$_version
= '20241009'
$client
public
BigQueryClient|null
$client
= \null
$core
public
mixed
$core
= \null
$dataset
public
Dataset
$dataset
= \null
$dataset_name
public
mixed
$dataset_name
= \null
$debug
public
mixed
$debug
= \false
$entity_schema
public
mixed
$entity_schema
= \null
$error
public
mixed
$error
= \false
$errorCode
public
mixed
$errorCode
= ''
$errorMsg
public
mixed
$errorMsg
= []
$fields
public
mixed
$fields
= []
$key
public
mixed
$key
= \null
$limit
public
mixed
$limit
= 0
$mapping
public
mixed
$mapping
= []
$offset
public
mixed
$offset
= 0
$options
public
mixed
$options
= []
$order
public
mixed
$order
= ''
$page
public
mixed
$page
= 0
$project_id
public
mixed
$project_id
= \null
$table
public
Table
$table
= \null
$table_name
public
mixed
$table_name
= \null
$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()
public
__construct(Core7 &$core, $params) : mixed
Parameters
_insertWithStreamingBuffer()
Insert a record in dataset.table
public
_insertWithStreamingBuffer( $data) : bool|null|void
Parameters
Return values
bool|null|voidaddError()
Adds an error message to the list of error messages.
public
addError(string $code, mixed $value) : bool
Parameters
- $code : string
-
The error code associated with the error message
- $value : mixed
-
The error message to be added
Return values
bool —Always returns false to facilitate the return of the caller
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
checkBigQueryStructure()
Return a structure with bigquery squema based on CF model
public
checkBigQueryStructure([mixed $fix = false ]) : array<string|int, mixed>
Parameters
- $fix : mixed = false
Return values
array<string|int, mixed>createDataSetTableInfo()
Creates a table in the given dataset with the specified fields.
public
createDataSetTableInfo(array<string|int, mixed> $fields[, string|null $dataset_name = null ][, string|null $table_name = null ]) : array<string|int, mixed>
Parameters
- $fields : array<string|int, mixed>
-
The schema of the table to be created.
- $dataset_name : string|null = null
-
The name of the dataset in which the table should be created. Defaults to the default dataset if not provided.
- $table_name : string|null = null
-
The name of the table to be created. Defaults to the default table name if not provided.
Return values
array<string|int, mixed> —An array containing information about the created table in the format of ['table' => 'project_id.dataset_name.table_id', 'info' => $table_info]. Returns false if an error occurs.
dbFeed()
Feed a table in Bigquery
public
dbFeed( $title, $table_id, &$data) : array<string|int, mixed>|void
Parameters
Return values
array<string|int, mixed>|voiddbQuery()
Execute a Query with a title
public
dbQuery( $title, $_q[, array<string|int, mixed> $params = [] ]) : array<string|int, mixed>|void
Parameters
Return values
array<string|int, mixed>|voiddelete()
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 $groupBy = null ][, mixed $params = [] ]) : array<string|int, mixed>|void
Parameters
- $keysWhere : array<string|int, mixed>|string = []
- $fields : null = null
- $groupBy : mixed = null
- $params : mixed = []
Return values
array<string|int, mixed>|voidfetchByKeys()
Return the tuplas with the $keyWhere including $fields
public
fetchByKeys( $keysWhere[, null $fields = null ]) : mixed
Parameters
fetchOne()
Return [record_structure]
public
fetchOne([array<string|int, mixed> $keysWhere = [] ][, null $fields = null ][, mixed $groupBy = null ][, mixed $params = [] ]) : array<string|int, mixed>|void
Parameters
- $keysWhere : array<string|int, mixed> = []
- $fields : null = null
- $groupBy : mixed = null
- $params : mixed = []
Return values
array<string|int, mixed>|voidfetchOneByKey()
Return one record based on a key
public
fetchOneByKey( $key[, null $fields = null ]) : mixed
Parameters
getBigQueryStructureFromModel()
Return a structure with bigquery squema based on CF model
public
getBigQueryStructureFromModel() : array<string|int, mixed>
Return values
array<string|int, mixed>getDataSetInfo()
Return information about the specified dataset.
public
getDataSetInfo([string|null $dataset_name = null ]) : array<string|int, mixed>|false
Parameters
- $dataset_name : string|null = null
-
The name of the dataset (default is null).
Return values
array<string|int, mixed>|false —Returns information about the dataset, including metadata and schema. false if error
getDataSets()
Return datasets associated to the project
public
getDataSets() : array<string|int, mixed>|false
Return values
array<string|int, mixed>|false —An array of dataset IDs or null if an error occurs
getDataSetTableInfo()
Retrieves information about the specified table in the given dataset or the default dataset.
public
getDataSetTableInfo([string|null $dataset_name = null ][, string|null $table_name = null ]) : array<string|int, mixed>|false
Parameters
- $dataset_name : string|null = null
-
The name of the dataset where the table is located. Defaults to the default dataset if not provided.
- $table_name : string|null = null
-
The name of the table to retrieve information for. Defaults to the default table if not provided.
Return values
array<string|int, mixed>|false —An array containing table information including table ID, fully qualified table ID, sample query, and table info. Returns false if an error occurs.
getDataSetTables()
Retrieves the tables in the given dataset or the default dataset.
public
getDataSetTables([string|null $dataset_name = null ]) : array<string|int, mixed>|false
Parameters
- $dataset_name : string|null = null
-
The name of the dataset to retrieve tables from. Defaults to the default dataset if not provided.
Return values
array<string|int, mixed>|false —An array of table IDs in the dataset. false if error
getDBQuery()
Return last query executed
public
getDBQuery() : null|string
Return values
null|stringgetDBQueryTime()
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|nullgetInterfaceModelFromDatasetTable()
Return a structure with bigquery squema based on CF model
public
getInterfaceModelFromDatasetTable() : array<string|int, mixed>
Return values
array<string|int, mixed>getMappingFields()
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()
public
getQuerySQLWhereAndParams([mixed $keysWhere = [] ]) : mixed
Parameters
- $keysWhere : mixed = []
getSQLSelectFields()
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()
Insert a record in db. If $upsert is true and the record exist then update it
public
insert( $data[, bool $upsert = false ]) : bool|null|void
Parameters
Return values
bool|null|voidinsertWithStreamingBuffer()
Inserts data with streaming buffer into the BigQuery table.
public
insertWithStreamingBuffer(array<string|int, mixed> $data) : array<string|int, mixed>|false
Parameters
- $data : array<string|int, mixed>
-
The data to be inserted into the BigQuery table. Must be an array with key -> value pairs.
Return values
array<string|int, mixed>|false —Returns the inserted data if successful. false if an error occurs during the insertion process.
join()
public
join( $type, DataBQ &$object, $first_field, $join_field[, $extraon = null ]) : mixed
Parameters
- $type :
-
Could be inner or left
- $object : DataBQ
- $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
onlyCreateQuery()
Define When I want to build a query but I do not want to be executed I call this method with true value
public
onlyCreateQuery( $boolean) : mixed
Parameters
query()
public
query(mixed $title, mixed $_q[, mixed $params = [] ]) : mixed
Parameters
- $title : mixed
- $_q : mixed
- $params : mixed = []
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
softDelete()
Update a record in db It requires to add always the following condition: and _created < TIMESTAMP_SUB(_created, INTERVAL 30 MINUTE) because you can not update or delete records inserted before 30' has passed
public
softDelete(mixed $key) : bool|null|void
Parameters
- $key : mixed
Return values
bool|null|voidtest()
Just a test query to know if the service works
public
test() : array<string|int, mixed>|void
Return values
array<string|int, mixed>|voidunsetOrder()
About Order
public
unsetOrder() : mixed
update()
Update a record in db It requires to add always the following condition: and _created < TIMESTAMP_SUB(_created, INTERVAL 30 MINUTE) because you can not update or delete records inserted before 30' has passed
public
update( $data[, mixed $record_readed = [] ]) : bool|null|void
Parameters
Return values
bool|null|voidupsert()
Upsert 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
_feed()
Feeds data into the specified BigQuery table.
private
_feed(string $table_id, array<string|int, mixed> &$data) : bool
Parameters
- $table_id : string
-
The ID of the table to feed data into.
- $data : array<string|int, mixed>
-
The data to be fed into the table.
Return values
bool —Returns true if the data insertion was successful. If an error occurs during data insertion, it will log the errors and returns false
_query()
Executes a query with optional parameters.
private
_query(string $q[, array<string|int, mixed> $params = [] ]) : array<string|int, mixed>|false
Parameters
- $q : string
-
The query string with optional placeholders for parameters.
- $params : array<string|int, mixed> = []
-
An array of parameters to be replaced in the query string (optional).
Return values
array<string|int, mixed>|false —An array of rows with queried data. false if an error occurs.
processSchema()
Process Schema
private
processSchema( $schema) : bool|void