Download the PHP package nonsapiens/bigquery-model-sync without Composer

On this page you can find all versions of the php package nonsapiens/bigquery-model-sync. 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 bigquery-model-sync

BigQuery Model Sync

A Laravel package to synchronize Eloquent models with Google BigQuery tables.

Installation

  1. Install the package via composer:

  2. Publish the configuration file and migrations:

  3. Run the migrations:

Configuration

The configuration is located at config/bigquery.php.

Environment Variables

Localhost vs WIF (Workload Identity Federation)

Localhost: Set BIGQUERY_CREDENTIALS in your .env file to the absolute path of your service account JSON key.

Deployed (WIF): When deployed on Google Cloud (GKE, Cloud Run, etc.) using Workload Identity Federation, you should NOT provide a service account key. The BigQueryClient will automatically use the environment's default credentials. Leave BIGQUERY_CREDENTIALS empty or unset in your production environment.

Usage

1. Prepare your Model

Add the SyncsToBigQuery trait to the models you want to synchronize.

2. Configure Model Settings (Optional)

You can customize the sync behavior by defining properties or methods in your model:

Property / Method Default Description
$fieldsToSync [] (all fields) Array of columns to sync.
$syncStrategy BATCH BATCH, REPLACE, or ON_INSERT.
$bigQueryTableName Model table name The target BigQuery table name.
$syncSchedule null Cron expression for when the model should sync.
$batchSize 10000 Number of records per batch.
$batchField sync_batch_uuid Database field used to track sync batches.

3. Create BigQuery Table

Generate the SQL required to create the table in BigQuery:

Copy the output and run it in the BigQuery console.

4. Prepare Database (if using BATCH or ON_INSERT)

If you are using BATCH (default) or ON_INSERT strategies, you need a tracking column in your local database. Generate a migration:

Syncing Strategies

Geodata Mapping

If your model contains latitude and longitude information, the package can automatically map these into a single GEOGRAPHY field in BigQuery.

Configuration

Add the following properties or methods to your model:

Property / Method Default Description
$hasGeodata false Set to true to enable geodata mapping.
$geodataFields ['latitude', 'longitude'] The source fields in your local database.
$mappedGeographyField geolocation The name of the GEOGRAPHY column in BigQuery.

How it Works

  1. Table Generation: When running php artisan make:bigquery-table, the package will exclude the individual latitude and longitude fields from the generated SQL and instead include a single GEOGRAPHY field (e.g., geolocation).
  2. Data Transformation: During synchronization, the package combines the latitude and longitude values into a WKT (Well-Known Text) POINT string: POINT(longitude latitude).
  3. BigQuery Storage: BigQuery stores this as a native GEOGRAPHY type, allowing you to use BigQuery GIS functions for spatial analysis.

Note: The interactive bigquery:set-model command will automatically detect if latitude and longitude fields are present and offer to configure this mapping for you.

Requirements for Schedule and Queue

Scheduling

The package includes a scheduled task that runs every minute to check if any models are due for synchronization based on their $syncSchedule.

To enable this, ensure the Laravel scheduler is running in your environment:

You can disable automatic scheduling by setting BIGQUERY_AUTOSYNC=false in your .env.

Queuing

The ON_INSERT strategy and the bigquery:sync --queue command rely on Laravel's queue system. Ensure you have a queue worker running:

Commands

bigquery:set-model

An interactive command to configure an Eloquent model for BigQuery synchronization. It guides you through selecting fields, configuring geodata mapping, and choosing a sync strategy.

make:bigquery-table

Generates the CREATE TABLE SQL required for BigQuery based on your Eloquent model's schema and configuration.

make:bigquery-model-migration

Creates a Laravel migration to add the required tracking column (default: sync_batch_uuid) to your model's database table.

bigquery:sync

Synchronizes a specific model with BigQuery. This command is typically called by the scheduler but can be run manually.

bigquery:sync-all

Discovers all models using the SyncsToBigQuery trait and runs their synchronization if they are due.

bigquery:truncate

Truncates the BigQuery tables associated with your models. Use with caution.


All versions of bigquery-model-sync with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
laravel/framework Version ^13.0|^12.0
google/cloud-bigquery Version ^1.36
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 nonsapiens/bigquery-model-sync contains the following files

Loading the files please wait ...