Download the PHP package colopl/laravel-spanner without Composer

On this page you can find all versions of the php package colopl/laravel-spanner. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-spanner

laravel-spanner

Laravel database driver for Google Cloud Spanner

License Latest Stable Version Minimum PHP Version

Requirements

Installation

Put JSON credential file path to env variable: GOOGLE_APPLICATION_CREDENTIALS

Install via composer

Add connection config to config/database.php

That's all. You can use database connection as usual.

Additional Configurations

You can pass SpannerClient config and CacheSessionPool options as below. For more information, please see Google Client Library docs

Recommended Setup

Please note that the following are not required, but are strongly recommended for better performance.

Unsupported features

Limitations

SQL Mode

Currently only supports Spanner running GoogleSQL (PostgreSQL mode is not supported).

Query

Eloquent

If you use interleaved keys, you MUST define them in the interleaveKeys property, or else you won't be able to save. For more detailed instructions, see Colopl\Spanner\Tests\Eloquent\ModelTest.

Additional Information

Migrations

Since Cloud Spanner does not support AUTO_INCREMENT attribute, Blueprint::increments (and all of its variants) will create a column of type STRING(36) DEFAULT (GENERATE_UUID()) to generate and fill the column with a UUID and flag it as a primary key.

Transactions

Google Cloud Spanner sometimes requests transaction retries (e.g. UNAVAILABLE, and ABORTED), even if the logic is correct. For that reason, please do not manage transactions manually.

You should always use the transaction method which handles retry requests internally.

Google Cloud Spanner creates transactions for all data operations even if you do not explicitly create transactions.

In particular, in the SELECT statement, the type of transaction varies depending on whether it is explicit or implicit.

Transaction type SELECT statement INSERT/UPDATE/DELETE statement
implicit transaction Read-only transaction with singleUse option Read-write transaction with singleUse option
explicit transaction Read-write transaction Read-write transaction

For more information, see Cloud Spanner Documentation about transactions

Stale reads

You can use Stale reads (timestamp bounds) as below.

Stale reads always runs as read-only transaction with singleUse option. So you can not run as read-write transaction.

Data Boost

Data boost creates snapshot and runs the query in parallel without affecting existing workloads.

You can read more about it here.

Below are some examples of how to use it.

[!NOTE] This creates a new session in the background which is not shared with the current session pool. This means, queries running with data boost will not be associated with transactions that may be taking place.

Request Tags and Transaction Tags

Spanner allows you to attach tags to your queries and transactions that can be used for troubleshooting.

You can set request tags and transaction tags as below.

Data Types

Some data types of Google Cloud Spanner does not have corresponding built-in type of PHP. You can use following classes by Google Cloud PHP Client

When fetching rows, the library coverts the following column types

Note that if you execute a query without QueryBuilder, it will not have these conversions.

Partitioned DML

You can run partitioned DML as below.

However, Partitioned DML has some limitations. See Cloud Spanner Documentation about Partitioned DML for more information.

Interleave

You can define interleaved tables as below.

Row Deletion Policy

You can define row deletion policy as below.

Sequence

If you want a simple sequence to be used as a primary key, you can use useSequence() method. If useSequence() is called without providing a $name, a sequence with name user_id_sequence will be created with start_with_counter set with a random value between 1 and 1,000,000.

If you want more flexibility, you can also create, alter, and drop sequences directly as below.

Change Streams

Spanner supports Change Streams which allows you to listen to changes in the database. Change streams can be created/altered/dropped through the schema builder as shown below.

Secondary Index Options

You can define Spanner specific index options like null filtering and storing as below.

Mutations

You can insert, update, and delete data using mutations to modify data instead of using DML to improve performance.

Please note that mutation api does not work the same way as DML. All mutations calls within a transaction are queued and sent as batch at the time you commit. This means that if you make any modifications through the above functions and then try to SELECT the same records before committing, the returned results will not include any of the modifications you've made inside the transaction.

SessionPool and AuthCache

In order to improve the performance of the first connection per request, we use AuthCache and CacheSessionPool.

By default, this library uses Filesystem Cache Adapter as the caching pool. If you want to use your own caching pool, you can extend ServiceProvider and inject it into the constructor of Colopl\Spanner\Connection.

The initialization of each session takes about a second, so warming up the sessions during the boot up phase of your server is recommended. This can be achieved by running the php artisan spanner:warmup command. You can set the number of sessions to warm up by setting the connections.{name}.session_pool.maxSessions option in config/database.php

Similarly, the sessions remain active for 60 minutes after use so deleting the sessions during the shutdown phase of your server is recommended. This can be achieved by running the php artisan spanner:cooldown command.

Queue Worker

After every job is processed, the connection will be disconnected so the session can be released into the session pool. This allows the session to be renewed (through maintainSessionPool()) or expire.

Laravel Tinker

You can use Laravel Tinker with commands such as php artisan tinker. But your session may hang when accessing Cloud Spanner. This is known gRPC issue that occurs when PHP forks a process. The workaround is to add following line to php.ini.

Development

Testing

You can run tests on docker by the following command. Note that some environment variables must be set. In order to set the variables, rename .env.sample to .env and edit the values of the defined variables.

Name Value
GOOGLE_APPLICATION_CREDENTIALS The path of the service account key file with access privilege to Google Cloud Spanner instance
DB_SPANNER_INSTANCE_ID Instance ID of your Google Cloud Spanner
DB_SPANNER_DATABASE_ID Name of the database with in the Google Cloud Spanner instance
DB_SPANNER_PROJECT_ID Not required if your credential includes the project ID

License

Apache 2.0 - See LICENSE for more information.


All versions of laravel-spanner with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
ext-grpc Version *
ext-json Version *
laravel/framework Version ^10.34.2
google/cloud-spanner Version ^1.58.4
grpc/grpc Version ^1.42
symfony/cache Version ~6
symfony/deprecation-contracts Version ~2
symfony/lock Version ~6
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package colopl/laravel-spanner contains the following files

Loading the files please wait ....