reedtechus/azure-data-explorer-laravel

Azure Data Explorer SDK for Laravel


README

logo-print-hd-transparent

Azure Data Explorer SDK for Laravel

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This project is a Laravel package that allows you to connect to Azure Data Explorer and execute queries from your Laravel Application.

⚠️ Experimental: This package is still in development and is not ready for production use. Breaking changes can still occur without a major version change until 1.0.0.

This package is a direct extension of the Azure Data Explorer SDK for PHP by Reed Tech which provides a PHP SDK to interact with the Azure Data Explorer REST API.

Goals

The goal of this project is to provide a Laravel friendly interface to the Azure Data Explorer SDK package.

Feature Roadmap

  • Caching via Redis

Installation

You can install the package via composer:

composer require reedtechus/azure-data-explorer-laravel

The following environment variables are required for this package to work:

# Azure Data Explorer
AZURE_DATA_EXPLORER_TENANT_ID="TENANT_ID"
AZURE_DATA_EXPLORER_CLIENT_ID="CLIENT_ID"
AZURE_DATA_EXPLORER_CLIENT_SECRET="SECRET"
AZURE_DATA_EXPLORER_CLUSTER="CLUSTER"
AZURE_DATA_EXPLORER_REGION="REGION"
AZURE_DATA_EXPLORER_DATABASE="DATABASE_NAME"

You can publish the config file with:

php artisan vendor:publish --tag="azure-data-explorer-laravel-config"

This is the contents of the published config file:

return [
	/*
    |--------------------------------------------------------------------------
    | Azure Data Explorer
    |--------------------------------------------------------------------------
    |
    | This is the configuration for the Azure Data Explorer package.
    |
    */

    // The base URL of the Azure Data Explorer API.
    'base_url' => env('AZURE_DATA_EXPLORER_BASE_URL', 'https://login.microsoftonline.com'),

    // The tenant ID of the Azure Data Explorer API.
    'tenant_id' => env('AZURE_DATA_EXPLORER_TENANT_ID'),

    // The client ID of the Azure Data Explorer API.
    'client_id' => env('AZURE_DATA_EXPLORER_CLIENT_ID'),

    // The client secret of the Azure Data Explorer API.
    'client_secret' => env('AZURE_DATA_EXPLORER_CLIENT_SECRET'),

    // The cache driver to use for caching responses.
    'cache_driver' => env('AZURE_DATA_EXPLORER_CACHE_DRIVER', 'redis'),

    // The cache TTL to use for caching responses.
    'cache_ttl' => env('AZURE_DATA_EXPLORER_CACHE_TTL', 3500),

    // The cluster of the Azure Data Explorer API.
    'cluster' => env('AZURE_DATA_EXPLORER_CLUSTER'),

    // The region of the Azure Data Explorer API.
    'region' => env('AZURE_DATA_EXPLORER_REGION'),

	// The database of the Azure Data Explorer API.
	'database' => env('AZURE_DATA_EXPLORER_DATABASE'),
];

Usage

// Option A: More efficient to save and re-use the AzureDataExplorer class instance for followup queries
$de = new AzureDataExplorer();
$results = $de->query($query);

// Option B: you can use the AzureDataExplorer::queryOnce() method to perform the query
$results = AzureDataExplorer::queryOnce($query);

These calls return a QueryResultsDTO object (or throw an exception).

Using the results

dump('Columns: '.implode(', ', $results->columns));
dump('Number of Results: '.count($results->data));
dump('Execution Time: '.$results->executionTime);

dump('First Row: '.print_r($results->data[0], true));

Testing

composer test

Dependencies

Changelog

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

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

This package is not endorsed nor supported by Microsoft in any way.

License

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