PHP code example of giginc / cakephp3-driver-bigquery

1. Go to this page and download the library: Download giginc/cakephp3-driver-bigquery library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

giginc / cakephp3-driver-bigquery example snippets


 'Datasources' => [
...
    'bigquery' => [
        'className' => 'Giginc\BigQuery\Database\Connection',
        'driver' => 'Giginc\BigQuery\Database\Driver\BigQuery',
        'projectId' => env('BIGQUERY_PROJECT_ID', 'project_id'),
        'dataSet' => env('BIGQUERY_DATASET', 'dataset'),
        'keyFile' => [], // Console. Ex: json_decode(file_get_contents($path), true).
        'keyFilePath' => null, //The full path to your service account credentials .json file retrieved.
        'requestTimeout' => 0, // Defaults to 0 with REST and 60 with gRPC.
        'retries' => 3, // Number of retries for a failed request. Defaults to 3.
        'location' => 'us', // If provided, determines the default geographic location used when creating datasets and managing jobs.
        'maximumBytesBilled' => 1000000,
    ],

],

//src/Model/Table/ProductsTable.php
namespace App\Model\Table;

use Giginc\BigQuery\ORM\Table;

/**
 * ProductsTable Table
 *
 * @uses Table
 * @package Table
 */
class ProductsTable extends Table
{
    public function initialize(array $config)
    {
        parent::initialize($config);

        $this->setTable('products_%Y%m%d');
        $this->setSchema([
            [
                "name" => "name",
                "type" => "STRING",
                "mode" => "NULLABLE",
            ],[
                "name" => "description",
                "type" => "STRING",
                "mode" => "NULLABLE",
            ],[
                "name" => "count",
                "type" => "INTEGER",
                "mode" => "NULLABLE",
            ],[
                "name" => "created_at",
                "type" => "DATETIME",
                "mode" => "NULLABLE",
            ],
        ]);
    }

    public static function defaultConnectionName()
    {
        return 'bigquery';
    }

    public function findOk($query, array $options)
    {
        $query = $query
            ->where([
                'status' => 'ok',
            ]);

        return $query;
    }
}

//src/Model/Entity/Product.php
namespace App\Model\Entity;

use Cake\ORM\Entity;

/**
 * Product Entity
 *
 * @uses Entity
 * @package Entity
 */
class Product extends Entity
{
    protected $_accessible = [
        '*' => true,
        'id' => false,
    ];

    protected $_virtual = [
    ];
}

## Controllers