Documentation

DataStore
in package

[$sql = $this->core->loadClass('DataStore');] Class to Handle Datastore databases with CloudFramework models

https://cloud.google.com/datastore/docs/concepts/entities

https://cloud.google.com/datastore/docs/concepts/queries#datastore-datastore-limit-gql

https://googleapis.github.io/google-cloud-php/#/docs/google-cloud/v0.121.0/datastore/datastoreclient

https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/datastore/api/src/functions/concepts.php

Table of Contents

Properties

$cache  : CoreCache
$cache_data  : mixed
$cacheSecretIV  : mixed
$cacheSecretKey  : mixed
$cursor  : mixed
$datastore  : DatastoreClient|null
$debug  : mixed
$default_time_zone_to_read  : mixed
$default_time_zone_to_write  : mixed
$entity_name  : mixed
$error  : mixed
$errorCode  : mixed
$errorMsg  : mixed
$last_cursor  : mixed
$lastQuery  : mixed
$limit  : mixed
$namespace  : mixed
$options  : mixed
$project_id  : mixed
$schema  : mixed
$service_account  : mixed
$transformReadedEntities  : mixed
$useCache  : mixed
$_version  : mixed
$core  : Core7

Methods

__construct()  : mixed
Cloudframework Datastore Constructor
activateCache()  : mixed
Set $this->useCache to true or false
addError()  : mixed
Add an error in the class
createEntities()  : array<string|int, mixed>|bool
Creating entities based in the schema
deactivateCache()  : mixed
delete()  : array<string|int, mixed>|bool|void
Delete using a where condition
deleteByKeys()  : array<string|int, mixed>|void
Delete receiving Keys
fetch()  : array<string|int, mixed>|false|void
Execute a Datastore Query taking the following parameters
fetchAll()  : mixed
fetchByKeys()  : array<string|int, mixed>
Return entities by Keys
fetchCount()  : int|mixed|null
Returns the number of records of the entity based on a condition.
fetchLimit()  : mixed
fetchOne()  : array<string|int, mixed>|bool
fetchOne, fetchAll, fetchLimit call to fetch($type)
fetchOneByKey()  : array<string|int, mixed>|void
Return entities by key
getCache()  : mixed|null
Return a cache key previously set
getCheckedRecordWithMapData()  : array<string|int, mixed>
Fill an array based in the model structure and mapped data
getEntityTemplate()  : array<string|int, mixed>
Fill an array based in the model structure and mapped data
getFormModelWithMapData()  : mixed
initCache()  : mixed
Init cache of the object
query()  : array<string|int, mixed>|void
Execute a Manual Query
resetCache()  : mixed
Reset the cache.
setCache()  : mixed
Assign cache $result based on $key
setError()  : mixed
Reset and set an error in the class
sum()  : int|null
Execute a Datastore aggregation sum Query over $field * https://cloud.google.com/datastore/docs/aggregation-queries
transformEntityInMapData()  : mixed
loadSchema()  : mixed
Return array with the schema format: { "field1":["type"(,"index|..other validations")] { "field2":["type"(,"index|..other validations")]
transformResult()  : array<string|int, mixed>|void
Transform Result of a query

Properties

$cache_data

public mixed $cache_data = \null

$cacheSecretIV

public mixed $cacheSecretIV = ''

$cacheSecretKey

public mixed $cacheSecretKey = ''

$datastore

public DatastoreClient|null $datastore = \null

$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

$namespace

public mixed $namespace = 'default'

$service_account

public mixed $service_account = \null

$transformReadedEntities

public mixed $transformReadedEntities = \true

$_version

protected mixed $_version = '20230927'

Methods

__construct()

Cloudframework Datastore Constructor

public __construct(Core7 &$core, array<string|int, mixed> $params) : mixed
Parameters
$core : Core7
$params : array<string|int, mixed>

[

  • @type string $entity_name Name of the Datastore entity. Optionally you can pass it as $params[0],

  • @type string $namespace [optional] Namspace of the Datastore entity. Optionally you can pass it as $params[1],

  • @type array $schema [optional] Eschema to define a CloudFramework Model for the Entity. Optionally you can pass it as $params[2]

  • @type array $options [optional] Optons for security and transport. Optionally you can pass it as $params[3]: [

    • @tyoe string $namespaceId [optional]
    • @tyoe string $projectId [optional]
    • @tyoe string $transport [optional] can be: grpc or rest. to stablish server protocol. Bu default is $core->config->get('core.datastore.transport') or rest
    • @tyoe array $keyFile [optional] you can pass a server token generated in GCP to stablish access permissions

    ]

]

activateCache()

Set $this->useCache to true or false

public activateCache([bool $activate = true ][, mixed $secretKey = '' ][, mixed $secretIV = '' ]) : mixed
Parameters
$activate : bool = true
$secretKey : mixed = ''
$secretIV : mixed = ''

addError()

Add an error in the class

public addError( $value) : mixed
Parameters
$value :

createEntities()

Creating entities based in the schema

public createEntities( $data[, mixed $transaction = false ]) : array<string|int, mixed>|bool
Parameters
$data :
$transaction : mixed = false
Return values
array<string|int, mixed>|bool

deactivateCache()

public deactivateCache([mixed $activate = true ]) : mixed
Parameters
$activate : mixed = true

delete()

Delete using a where condition

public delete( $where) : array<string|int, mixed>|bool|void
Parameters
$where :
Return values
array<string|int, mixed>|bool|void

deleteByKeys()

Delete receiving Keys

public deleteByKeys( $keys) : array<string|int, mixed>|void
Parameters
$keys :

array|string if string can be values separated by ','. If array can be an array of string,integer elements

Return values
array<string|int, mixed>|void

fetch()

Execute a Datastore Query taking the following parameters

public fetch([string $type = 'one' ][, string $fields = '*' ][, null $where = null ][, null $order = null ][, null $limit = null ]) : array<string|int, mixed>|false|void
Parameters
$type : string = 'one'
$fields : string = '*'
$where : null = null
$order : null = null
$limit : null = null
Tags
throws
Exception
Return values
array<string|int, mixed>|false|void

fetchAll()

public fetchAll([mixed $fields = '*' ][, mixed $where = null ][, mixed $order = null ]) : mixed
Parameters
$fields : mixed = '*'
$where : mixed = null
$order : mixed = null

fetchByKeys()

Return entities by Keys

public fetchByKeys(array<string|int, mixed>|string $keys) : array<string|int, mixed>
Parameters
$keys : array<string|int, mixed>|string

if string can be values separated by ','. If array can be an array of string,integer elements

Return values
array<string|int, mixed>

fetchCount()

Returns the number of records of the entity based on a condition.

public fetchCount([null $where = null ][, string $distinct = '__key__' ]) : int|mixed|null

Uses cache to return results

Parameters
$where : null = null
$distinct : string = '__key__'
Return values
int|mixed|null

fetchLimit()

public fetchLimit([mixed $fields = '*' ][, mixed $where = null ][, mixed $order = null ][, mixed $limit = null ]) : mixed
Parameters
$fields : mixed = '*'
$where : mixed = null
$order : mixed = null
$limit : mixed = null

fetchOne()

fetchOne, fetchAll, fetchLimit call to fetch($type)

public fetchOne([string $fields = '*' ][, null $where = null ][, null $order = null ]) : array<string|int, mixed>|bool
Parameters
$fields : string = '*'
$where : null = null
$order : null = null
Return values
array<string|int, mixed>|bool

fetchOneByKey()

Return entities by key

public fetchOneByKey(int|string $key) : array<string|int, mixed>|void
Parameters
$key : int|string
Return values
array<string|int, mixed>|void

with the element

getCache()

Return a cache key previously set

public getCache( $key) : mixed|null
Parameters
$key :
Return values
mixed|null

getCheckedRecordWithMapData()

Fill an array based in the model structure and mapped data

public getCheckedRecordWithMapData( $data[, mixed $all = true ][, array<string|int, mixed> &$dictionaries = [] ]) : array<string|int, mixed>
Parameters
$data :
$all : mixed = true
$dictionaries : array<string|int, mixed> = []
Return values
array<string|int, mixed>

getEntityTemplate()

Fill an array based in the model structure and mapped data

public getEntityTemplate([mixed $transform_keys = true ]) : array<string|int, mixed>
Parameters
$transform_keys : mixed = true
Return values
array<string|int, mixed>

getFormModelWithMapData()

public getFormModelWithMapData() : mixed

initCache()

Init cache of the object

public initCache() : mixed

query()

Execute a Manual Query

public query( $_q[,  $bindings = [] ]) : array<string|int, mixed>|void
Parameters
$_q :
$bindings : = []
Return values
array<string|int, mixed>|void

resetCache()

Reset the cache.

public resetCache() : mixed

setCache()

Assign cache $result based on $key

public setCache( $key,  $result) : mixed
Parameters
$key :
$result :

setError()

Reset and set an error in the class

public setError( $value) : mixed
Parameters
$value :

sum()

Execute a Datastore aggregation sum Query over $field * https://cloud.google.com/datastore/docs/aggregation-queries

public sum(string $field[, array<string|int, mixed> $where = [] ]) : int|null
Parameters
$field : string
$where : array<string|int, mixed> = []
Return values
int|null

If error it will return null

transformEntityInMapData()

public transformEntityInMapData(mixed $entity) : mixed
Parameters
$entity : mixed

loadSchema()

Return array with the schema format: { "field1":["type"(,"index|..other validations")] { "field2":["type"(,"index|..other validations")]

private loadSchema(mixed $entity, mixed $schema) : mixed
Parameters
$entity : mixed
$schema : mixed

transformResult()

Transform Result of a query

private transformResult( &$result) : array<string|int, mixed>|void
Parameters
$result :
Return values
array<string|int, mixed>|void

        
On this page

Search results