All Projects → prologuetech → laravel-big

prologuetech / laravel-big

Licence: MIT License
Google BigQuery for Laravel

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-big

flight2bq
RTLSDR ADS-B dump1090 to Google BigQuery
Stars: ✭ 33 (+135.71%)
Mutual labels:  bigquery, google-bigquery
snowplow-bigquery-loader
Loads Snowplow enriched events into Google BigQuery
Stars: ✭ 15 (+7.14%)
Mutual labels:  bigquery, google-bigquery
laravel-blade-macro
Blade `@macro` directive
Stars: ✭ 14 (+0%)
Mutual labels:  laravel-5-package
adminlte-laravel-installer
adminlte-laravel-installer . Installer for project acacha/adminlte-laravel
Stars: ✭ 16 (+14.29%)
Mutual labels:  laravel-5-package
carto-spatial-extension
A set of UDFs and Procedures to extend BigQuery, Snowflake, Redshift and Postgres with Spatial Analytics capabilities
Stars: ✭ 131 (+835.71%)
Mutual labels:  bigquery
model-observers
Make model observers easy
Stars: ✭ 17 (+21.43%)
Mutual labels:  laravel-5-package
laravel-browser-filter
Laravel middleware to filter routes based on browser types & versions.
Stars: ✭ 20 (+42.86%)
Mutual labels:  laravel-5-package
airflow-tutorial
Use Airflow to move data from multiple MySQL databases to BigQuery
Stars: ✭ 96 (+585.71%)
Mutual labels:  bigquery
laravel-video-api
Laravel (Youtube/Vimeo) Video Data API
Stars: ✭ 53 (+278.57%)
Mutual labels:  laravel-5-package
Base62
PHP Base62 encoder and decoder for integers and big integers with Laravel 5 support.
Stars: ✭ 16 (+14.29%)
Mutual labels:  laravel-5-package
docxmustache
laravel 8.x docx template manipulation class, based on mustache templating language
Stars: ✭ 34 (+142.86%)
Mutual labels:  laravel-5-package
dbq
CLI tool to easily Decorate BigQuery table name
Stars: ✭ 13 (-7.14%)
Mutual labels:  bigquery
target-and-market
A data-driven tool to identify the best candidates for a marketing campaign and optimize it.
Stars: ✭ 19 (+35.71%)
Mutual labels:  bigquery
bigquery-geo-viz
Visualize Google BigQuery geospatial data using Google Maps Platform APIs
Stars: ✭ 68 (+385.71%)
Mutual labels:  bigquery
laravel-jira-rest-client
A Laravel interface for your Atlassians Jira application
Stars: ✭ 37 (+164.29%)
Mutual labels:  laravel-5-package
laravel-string-similarities
Compare two string and get a similarity percentage
Stars: ✭ 54 (+285.71%)
Mutual labels:  laravel-5-package
gcp-ml
Google Cloud Platform Machine Learning Samples
Stars: ✭ 31 (+121.43%)
Mutual labels:  bigquery
laravel-camelcase-json
Convert response JSON key to camelCase
Stars: ✭ 23 (+64.29%)
Mutual labels:  laravel-5-package
LaravelFtp
Laravel FTP client
Stars: ✭ 15 (+7.14%)
Mutual labels:  laravel-5-package
pre-commit-dbt
🎣 List of `pre-commit` hooks to ensure the quality of your `dbt` projects.
Stars: ✭ 149 (+964.29%)
Mutual labels:  bigquery

Google BigQuery for Laravel

This package aims to wrap laravel functionality around Google's BigQuery.

Install

Via Composer

$ composer require prologuetech/big

Setup

Publish our config file into your application:

php artisan vendor:publish --provider="Prologuetech\Big\BigServiceProvider"

You should have a config/prologue-big.php file to configure defaults.

Laravel 5.4.x

Older versions of Laravel require you to add our big service provider to your application providers array in config/app.php:

Prologuetech\Big\BigServiceProvider::class,

You now have access to a familiar laravel experience, enjoy!

Google Authentication

The Google SDK supports Application Default Credentials (ADC) and thus this package does as well. You may leave your auth_file field inside of your config file null to use ADC. Credentials fetcher is not currently supported but may be added in the future.

For more information see the adc docs.

How to use

Configuration

By default we use the following global config options with BigQuery.

$this->options = [
    'useLegacySql' => false,
    'useQueryCache' => false,
];

Tables

When creating tables in BQ we automatically flip a Eloquent model schema for you. Let's cover an example of archiving data from our events table into BQ using laravel's chunk method.

$datasetId = 'test';
$tableId = 'events';

// Create our BQ helper
$big = new Big();

// Create table, we will pass in a mocked model to mutate into BQ schema
// Note: create table will only make a new table if it does not exist

/** @var Google\Cloud\BigQuery\Table $table */
$table = $big->createFromModel($datasetId, $tableId, new Event());

// Let's stream our events into BQ in large chunks
// Note: notArchived() is a simple scope, use whatever scopes you have on your model
Event::notArchived()->chunk(1000, function ($events) use ($big, $table) {
    // Prepare our rows
    $rows = $big->prepareData($events);

    // Stream into BQ, you may also pass in any options with a 3rd param.
    // Note: By default we use: 'ignoreUnknownValues' => true
    $big->insert($table, $rows);

    // Get our current id's
    /** @var Illuminate\Support\Collection $events */
    $ids = $events->pluck('id')->toArray();

    // Update these event's as processed
    Event::whereIn('id', $ids)->update([
        'system_processed' => 1
    ]);
});

That's it! You now have a replica of your events table in BigQuery, enjoy!

Queries

Instantiating Big will automatically setup a Google ServiceBuilder and give us direct access to BigQuery through our internals via $big->query. However there are many helpers built into Big that make interacting with BigQuery a piece of cake (or a tasty carrot if you're into that kind of thing).

For example when running a query on BigQuery we must use the reload method in a loop to poll results. Big comes with a useful method run so all you need to do is this:

$query = 'SELECT count(id) FROM test.events';

$big = new Big();
$results = $big->run($query);

When using run we automatically poll BigQuery and return all results as a laravel collection object for you so you can enjoy your results as a refreshing cup of Laravel.

Change log

Please see CHANGELOG for more information on what has changed recently.

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].