PHP code example of moirei / hogql

1. Go to this page and download the library: Download moirei/hogql library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

moirei / hogql example snippets


use MOIREI\HogQl\Facade as HogQl;
...

HogQl::select(['event_name', 'COUNT(*) as event_count'])
                ->whereBetween('timestamp', ['2024-01-01 12:00:00', '2024-07-28 10:15:39'])
                ->groupBy('event_name')
                ->orderBy('event_count', 'DESC')
                ->get();

$query = HogQl::query();
// OR
$query = HogQl::query('some_other_table');

$result = $query->get();

$query = HogQl::select('properties.$os as os')->where('os', 'iOS');
$result = $query->count();

// config/hogql.php
...
    'aliases' => [
        'device' => 'properties.$device',
        'os' => 'properties.$os',
        ...
    ],

$query = HogQl::select(['device', 'os']);
$result = $query->get();

$query = HogQl::model();
// OR
$query = HogQl::eloquent();

$result = $query->select(['properties.$current_url', 'properties.$device'])->get();

$query = HogQl::parse('SELECT event FROM events');
$result = $query->where('properties.my_user', $user->id)->count();

$response = HogQl::get('SELECT event, COUNT() FROM events GROUP BY event ORDER BY COUNT() DESC');

$response = HogQl::getRaw('SELECT event, COUNT() FROM events GROUP BY event ORDER BY COUNT() DESC');

$query = HogQl::eloquent()->where('event', '$pageview');

$metrics = Trend::make()
            ->name('Page views')
            ->period('week')
            ->sumByDays($query);
bash
php artisan vendor:publish --tag="hogql-config"