moirei/hogql 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

moirei/hogql

Composer 安装命令:

composer require moirei/hogql

包简介

Interact with PostHog's HogQL API using Laravel's query builder.

README 文档

README

This PostHog (HogQL) Laravel Query Builder package enables you to interact with PostHog's HogQL API using Laravel's query builder. This package simplifies the process of building and executing analytical queries, allowing you to leverage Laravel's intuitive query syntax while working with PostHog's powerful data analytics platform.

Features

  • Familiar Syntax: Use Laravel's query builder syntax to construct complex queries.
  • Secure Access: Validate and restrict access to specific tables within PostHog.
  • Seamless Integration: Execute queries and retrieve results directly from PostHog.
  • Configurable Aliases: Easily map and alias table and column names for better readability.
  • Eloquent Metrics: Easily integrate and use with moirei/eloquent-metrics.

Installation

composer require moirei/hogql

Publish the config (optional).

php artisan vendor:publish --tag="hogql-config"

Setup

After installation, you'll need to obtain your Product ID and a personal API key. This key will need atleast query:read scope.

Update your .env file with POSTHOG_PRODUCT_ID and POSTHOG_API_TOKEN accordingly.

Usage

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();

Note: the get() operation always transforms the raw result. E.g. the query above returns a collection of arrays with event_name and event_count keys/values.

Extended usage

Get a DB Query Builder instance:

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

$result = $query->get();

Start a query with select statement:

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

Referencing aliases:

Setup aliases in config:

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

Reference them via selects:

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

Get an Eloquent Query Builder instance:

Returns eloquent model instances.

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

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

Parse a query string:

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

Get the results of a string query:

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

Get the raw results of a string query:

Returns the raw original HogQLQueryResponse response.

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

With moirei/eloquent-metrics:

moirei/eloquent-metrics is Chartjs compatible.

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

$metrics = Trend::make()
            ->name('Page views')
            ->period('week')
            ->sumByDays($query);

Tests

composer test

Contribution Guidelines

Any pull requests or discussions are welcome. Note that every pull request providing new feature or correcting a bug should be created with appropriate unit tests.

License

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

moirei/hogql 适用场景与选型建议

moirei/hogql 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 172 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 07 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「query」 「laravel」 「moirei」 「posthog」 「hogql」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 moirei/hogql 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 moirei/hogql 我们能提供哪些服务?
定制开发 / 二次开发

基于 moirei/hogql 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 172
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 26
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-07-29