PHP code example of pelfox / laravel-bigquery
1. Go to this page and download the library: Download pelfox/laravel-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/ */
pelfox / laravel-bigquery example snippets
'bigquery' => [
'driver' => 'bigquery',
'database' => '',
'prefix' => '',
// default the id of the dataset to request
'dataset' => 'replace on dataset from bigquery', //
\Pelfox\LaravelBigQuery\Facades\BigQuery::dataset('dataset')->...
// Query Builder
DB::connection('bigquery')->table('table')->...
#for special dataset
DB::connection('bigquery')->table('dataset.table')->...
// Eloquent
class Table extends Model
{
protected $connection = 'bigquery';
#for special dataset
protected $table = 'dataset.table';
public $incrementing = false;
public $timestamps = false;
}
'field' => AsString::class . ':1'
'field' => AsString::class . ':0,getSchemaForFieldColumn'
namespace App\Models;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Pelfox\LaravelBigQuery\Eloquent\Casts\AsBigNumeric;
use Pelfox\LaravelBigQuery\Eloquent\Casts\AsBoolean;
use Pelfox\LaravelBigQuery\Eloquent\Casts\AsBytes;
use Pelfox\LaravelBigQuery\Eloquent\Casts\AsDate;
use Pelfox\LaravelBigQuery\Eloquent\Casts\AsDateTime;
use Pelfox\LaravelBigQuery\Eloquent\Casts\AsFloat;
use Pelfox\LaravelBigQuery\Eloquent\Casts\AsInteger;
use Pelfox\LaravelBigQuery\Eloquent\Casts\AsJson;
use Pelfox\LaravelBigQuery\Eloquent\Casts\AsNumeric;
use Pelfox\LaravelBigQuery\Eloquent\Casts\AsString;
use Pelfox\LaravelBigQuery\Eloquent\Casts\AsStruct;
use Pelfox\LaravelBigQuery\Eloquent\Casts\AsTime;
use Pelfox\LaravelBigQuery\Eloquent\Casts\AsTimestamp;
use Pelfox\LaravelBigQuery\Types\IntegerType;
use Pelfox\LaravelBigQuery\Types\StringType;
class Test extends Model
{
use HasFactory, HasUuids;
protected $table = 'test';
public $timestamps = false;
protected $connection = 'bigquery';
protected $fillable = [
'string', 'integer', 'bytes', 'float', 'numeric', 'bignumeric',
'boolean', 'timestamp', 'date', 'time', 'datetime',
'record', 'json', 'strings', 'struct'
];
protected $casts = [
'string' => AsString::class,
'strings' => AsString::class . ':1',
'bytes' => AsBytes::class,
'integer' => AsInteger::class,
'float' => AsFloat::class,
'numeric' => AsNumeric::class,
'bignumeric' => AsBigNumeric::class,
'boolean' => AsBoolean::class,
'timestamp' => AsTimestamp::class,
'date' => AsDate::class,
'time' => AsTime::class,
'datetime' => AsDateTime::class,
'record' => AsStruct::class . ':0,getSchemaForRecord',
'json' => AsJson::class,
'struct' => AsStruct::class . ':0,getSchemaForStruct'
];
public function getSchemaForRecord(): array
{
return [
'string' => StringType::class
];
}
public function getSchemaForStruct(): array
{
return [
'string' => StringType::class,
'integer' => IntegerType::class,
'names' => [StringType::class],
'struct' => [
'string' => StringType::class,
'integer' => IntegerType::class,
],
'array' => [
[
'string' => StringType::class,
'integer' => IntegerType::class
]
]
];
}
}