1. Go to this page and download the library: Download colopl/laravel-spanner 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/ */
// `default_sequence_kind` must be set in order to use auto increment
$schemaBuilder->setDatabaseOptions([
'default_sequence_kind' => 'bit_reversed_positive',
]);
$schemaBuilder->create('user', function (Blueprint $table) {
$table->integer('id')->primary()->autoIncrement();
});
// BAD: Do not use transactions manually!!
try {
DB::beginTransaction();
...
DB::commit();
} catch (\Throwable $ex) {
DB::rollBack();
}
// GOOD: You should always use transaction method
DB::transaction(function() {
...
});
// There are four types of timestamp bounds: ExactStaleness, MaxStaleness, MinReadTimestamp and ReadTimestamp.
$timestampBound = new ExactStaleness(10);
// by Connection
$connection->selectWithTimestampBound('SELECT ...', $bindings, $timestampBound);
// by Query Builder
$queryBuilder
->withStaleness($timestampBound)
->get();
$timestampBound = new ExactStaleness(10);
// by Connection
$connection->snapshot($timestampBound, function() use ($connection) {
$result1 = $connection->table('foo')->get();
$result2 = $connection->table('bar')->get();
return [$result1, $result2];
);
// by Model
User::where('foo', 'bar')
->snapshot($timestampBound)
->get();
// by Query Builder
$queryBuilder
->snapshot($timestampBound)
->get();
// Using Connection
$connection->selectWithOptions('SELECT ...', $bindings, ['dataBoostEnabled' => true]);
// Using Query Builder
$queryBuilder
->useDataBoost()
->setRequestTimeoutSeconds(60)
->get();
$schemaBuilder->create('user', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('name');
// adds an invisible column for full text search
$table->tokenList('UserNameTokens', TokenizerFunction::FullText, 'name', ['language_tag' => 'en']);
// adds a SEARCH INDEX
$table->fullText(['UserNameTokens']);
});
User::query()->searchFullText('UserNameTokens', 'John OR Kevin', ['enhance_query' => true])->get();