igorsgm/laravel-redash

📊 • A Laravel wrapper to empower your applications with Redash.io APIs. Extract, analyze, and leverage your Redash data right from your app!

1.1.0 2024-10-29 11:54 UTC

This package is auto-updated.

Last update: 2024-10-29 11:55:34 UTC


README

Unleash the power of Redash.io APIs in your Laravel applications. This package allows you to easily extract, analyze, and leverage your data directly within your application. Transform your data management today!

Latest Version on Packagist GitHub Tests Action Status Test Coverage Code Quality Total Downloads

✨ Features

  • Queries: Easily create, edit, or archive query objects directly from your Laravel application. The package returns paginated arrays of query objects and supports the extraction of individual query objects too.
  • Query Results: Initiate a new query execution or return a cached result effortlessly. Handle parameterized queries and manage max_age for cache bypassing with provided methods.
  • Dashboards: Create, edit, or archive dashboard objects seamlessly. Fetch an array of dashboard objects or individual ones directly from your Laravel application.
  • Jobs: Monitor the status of your query tasks effectively.

1️⃣ Installation

  • You can install the package via composer:
composer require igorsgm/laravel-redash
  • You can publish the config file with:
php artisan vendor:publish --tag="laravel-redash-config"

2️⃣ Usage

Define Redash API credentials in your .env file. i.e.:

REDASH_BASE_URL=foo:bar
REDASH_API_KEY=12345678900987654321

Summary

Queries

// Returns a paginated array of query objects.
Redash::queries()->all();

// Returns an individual query object.
Redash::queries()->get($queryId);

// Create a new query object.
Redash::queries()->create([
    'name' => 'My Query',
    'data_source_id' => 1,
    'query' => 'SELECT * FROM table',
    'description' => 'My Query Description',
    // ...
]);

// Edit an existing query object.
Redash::queries()->update($queryId, [
    'name' => 'My New Query Name',
    // ...
]);

// Archive an existing query.
Redash::queries()->delete($queryId);

// Get a cached result for this query ID
Redash::queries()->getCachedResult($queryId);

// Initiates a new query execution or returns a cached result.
Redash::queries()->executeOrGetResult($queryId, [
    'parameters' => [
        'foo' => 'bar',
    ],
    'max_age' => 0,
]);
  • Execute a Query and return its result once ready (custom method).
// The maximum age (in milliseconds) of a cached result that the method should return.
// If a cached result is older than this, a new query execution will begin.
// Set to `0` to always start a new execution.
$maxAge = 1800;

// The number of times to retry the query execution if it is still in progress.
$retryAttempts = 20;

Redash::queries()->getResult($queryId, [
    'foo' => 'bar',
], $maxAge, $retryAttempts);

Query Results

// Returns a query result
Redash::queryResults()->get($queryResultId);

Dashboards

Redash::dashboards()->all();
Redash::dashboards()->get($dashboardId);
Redash::dashboards()->create([
    // ...
]);
Redash::dashboards()->update($dashboardId, [
    // ...
]);
Redash::dashboards()->delete($dashboardId);

Jobs

Redash::jobs()->get($jobId);

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email igor.sgm@gmail.com instead of using the issue tracker.

Credits

License

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