PHPackages                             upscale/newrelic-query-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. upscale/newrelic-query-builder

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

upscale/newrelic-query-builder
==============================

Query builder for New Relic Query Language (NRQL)

1.0.0(11y ago)225Apache-2.0PHPPHP &gt;=5.3.0

Since Mar 8Pushed 11y ago1 watchersCompare

[ Source](https://github.com/upscalesoftware/newrelic-query-builder)[ Packagist](https://packagist.org/packages/upscale/newrelic-query-builder)[ Docs](https://github.com/upscalesoftware/newrelic-query-builder)[ RSS](/packages/upscale-newrelic-query-builder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

[![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": {
        "upscale/newrelic-query-builder": "*"
    }
}
```

Usage
-----

[](#usage)

The example below demonstrates a query with all available clauses:

```
use Upscale\Nrql\QueryBuilder;
use Upscale\Nrql\TimePeriod;
use Upscale\Nrql\Moment\TimeAgo;
use Upscale\Nrql\Moment\ExactTime;
use Upscale\Nrql\Moment\Yesterday;

$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 \DateTime('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

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

4089d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9ff1791f1bd72221702e39e356c25b108de26dea1f5b56416f7957e8fa43ea92?d=identicon)[upscalesoftware](/maintainers/upscalesoftware)

---

Tags

Insightsquery buildernewrelicnew relicNRQL

### Embed Badge

![Health badge](/badges/upscale-newrelic-query-builder/health.svg)

```
[![Health](https://phpackages.com/badges/upscale-newrelic-query-builder/health.svg)](https://phpackages.com/packages/upscale-newrelic-query-builder)
```

###  Alternatives

[intouch/laravel-newrelic

Laravel 5 NewRelic Integration

1731.2M](/packages/intouch-laravel-newrelic)[intouch/newrelic

Namespaced Wrapper for NewRelic PHP Agent

373.8M15](/packages/intouch-newrelic)[sobanvuex/php-newrelic

PHP Library for New Relic Agent

16520.7k5](/packages/sobanvuex-php-newrelic)[upscale/swoole-newrelic

New Relic APM monitoring of Swoole web-server

1619.6k](/packages/upscale-swoole-newrelic)

PHPackages © 2026

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