PHPackages                             rapiddive/nrql-builder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. rapiddive/nrql-builder

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

rapiddive/nrql-builder
======================

Query builder for New Relic Query Language (NRQL)

1.0.2(2mo ago)016Apache-2.0PHPPHP &gt;=8.0 | &gt;=7.4CI passing

Since Aug 28Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/rapiddive/nrql-builder)[ Packagist](https://packagist.org/packages/rapiddive/nrql-builder)[ RSS](/packages/rapiddive-nrql-builder/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (5)Used By (0)

INSPIRRED FROM

[![Build Status](https://camo.githubusercontent.com/463559b26f33442f43cdf512005cadb3404603cae39962292284dc692bcd0d68/68747470733a2f2f6170692e7472617669732d63692e6f72672f75707363616c65736f6674776172652f6e657772656c69632d71756572792d6275696c6465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/upscalesoftware/newrelic-query-builder)

Query Builder for NRQL
======================

[](#query-builder-for-nrql)

The New Relic Query Language (NRQL) is an SQL-flavored query language for making calls against the Insights Events database.

This project is a PHP library for assembling NRQL queries in object-oriented applications. Library implements the official [NRQL specification](https://docs.newrelic.com/docs/insights/new-relic-insights/using-new-relic-query-language/nrql-reference). It offers a "fluent" interface to specify query parts in an arbitrary order. That allows different application parts to influence the query w/o worrying about the query assembly order. Query integrity validation is performed upon rendering. Library provides object-oriented representation for complex elements of NRQL syntax. That enables code completion and avoids typos in contrast to plain text queries.

Installation
------------

[](#installation)

Library is to be installed via [Composer](https://getcomposer.org/) as a project dependency in `composer.json`:

```
{
    "require": {
        "rapiddive/nrql-builder": "*"
    }
}
```

Usage
-----

[](#usage)

The example below demonstrates a query with all available clauses:

```
use Carbon\Carbon;
use Rapiddive\NrqlBuilder\Moment\ExactTime;
use Rapiddive\NrqlBuilder\Moment\TimeAgo;
use Rapiddive\NrqlBuilder\Moment\Yesterday;
use Rapiddive\NrqlBuilder\QueryBuilder;
use Rapiddive\NrqlBuilder\TimePeriod;

$nrql = new QueryBuilder();
$nrql->select([
    'userAgentName',
])
    ->from([
        'PageView',
    ])
    ->where('userAgentOS = "Windows"')
    ->facet('countryCode')
    ->limit(20)
    ->since(new TimeAgo(new TimePeriod(4, TimePeriod::UNIT_DAYS)))
    ->until(new Yesterday())
    ->compareWith(new ExactTime(new Carbon('2015-01-01 00:00:00')))
    ->timeSeries(new TimePeriod(1, TimePeriod::UNIT_HOURS));

echo $nrql;
```

Limitations
-----------

[](#limitations)

Some complex aspects of the NRQL syntax have not been implemented in an object-oriented manner. These include [Aggregator Functions](https://docs.newrelic.com/docs/insights/new-relic-insights/using-new-relic-query-language/nrql-reference#functions), [Math Operators](https://docs.newrelic.com/docs/insights/new-relic-insights/using-new-relic-query-language/nrql-math) and logical operators (`AND`, `OR`, grouping). However, the library allows to utilize as complex expressions as needed in place of string arguments.

Free-format string arguments:

- Attributes of `SELECT` statement, including optional `AS` clause
- Conditions of `WHERE` clause
- Attribute of `FACET` clause

License
-------

[](#license)

Licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0).

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance84

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~273 days

Total

3

Last Release

82d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3eb6cb36cb128b6bcd97e40cd881784a2cad0b1cd8f363f98edf5ffdf416c57a?d=identicon)[vinayshah5](/maintainers/vinayshah5)

---

Top Contributors

[![vinayshah](https://avatars.githubusercontent.com/u/4420182?v=4)](https://github.com/vinayshah "vinayshah (20 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rapiddive-nrql-builder/health.svg)

```
[![Health](https://phpackages.com/badges/rapiddive-nrql-builder/health.svg)](https://phpackages.com/packages/rapiddive-nrql-builder)
```

###  Alternatives

[ashallendesign/short-url

A Laravel package for creating shortened URLs for your web apps.

1.4k1.9M4](/packages/ashallendesign-short-url)[solspace/craft-freeform

The most flexible and user-friendly form building plugin!

52664.9k12](/packages/solspace-craft-freeform)[intervention/zodiac

Zodiac Sign Calculator

58191.7k](/packages/intervention-zodiac)[erlandmuchasaj/laravel-gzip

Gzip your responses.

40129.3k2](/packages/erlandmuchasaj-laravel-gzip)[solspace/craft-calendar

The most powerful event management and calendaring plugin!

1830.8k1](/packages/solspace-craft-calendar)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
