PHPackages                             burnbright/silverstripe-sqlquerylist - 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. burnbright/silverstripe-sqlquerylist

Abandoned → [silvershop/silverstripe-sqlquerylist](/?search=silvershop%2Fsilverstripe-sqlquerylist)Silverstripe-vendormodule

burnbright/silverstripe-sqlquerylist
====================================

Wraps a SilverStripe SQLQuery in a SS\_List

3.1.0(2mo ago)423.5k5BSD-3-ClausePHPPHP ^8.1CI failing

Since Sep 12Pushed 2mo ago5 watchersCompare

[ Source](https://github.com/silvershop/silverstripe-sqlquerylist)[ Packagist](https://packagist.org/packages/burnbright/silverstripe-sqlquerylist)[ RSS](/packages/burnbright-silverstripe-sqlquerylist/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (5)Versions (10)Used By (0)

SilverShop SQLQueryList
=======================

[](#silvershop-sqlquerylist)

Create DB-driven `SS_List` instances from a SilverStripe `SQLSelect` query. Use them in templates and code like a `DataList` for **display, iteration, counting, sorting, and limiting**—without loading all rows into memory. Ideal for reporting and custom SQL-backed lists.

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

[](#installation)

```
composer require silvershop/silverstripe-sqlquerylist
```

Why use it?
-----------

[](#why-use-it)

The SilverStripe ORM doesn’t let you treat arbitrary SQL as a list. Turning a `SQLQuery` result into an `ArrayList` forces loading every row into memory, which can be expensive or impossible for large result sets.

`SQLQueryList` wraps a `SQLSelect` and implements `SS_List`, so you get:

- **Lazy execution** – rows are only fetched when you iterate or call `toArray()`
- **Efficient `count()`** – uses a `COUNT` query instead of loading all rows
- **Efficient `first()` and `find()`** – use `LIMIT 1` under the hood
- **Sorting and limiting** – `sort()`, `limit()`, and `where()` modify the underlying query
- **Template-friendly** – pass the list to templates and loop with `$List`, paginate, etc.

**Limitations:** The list is **read-only**. You cannot add, remove, or mutate records. Methods like `filter()`, `exclude()`, `map()`, `column()`, and array access are not supported; build those constraints into your `SQLSelect` or use `where()` / `sort()` / `limit()` where available.

---

Basic usage
-----------

[](#basic-usage)

Build a `SQLSelect` and wrap it in `SQLQueryList`:

```
use SilverShop\SQLQueryList\SQLQueryList;
use SilverStripe\ORM\Queries\SQLSelect;

$query = SQLSelect::create(
    ['"Title"', '"ID"', '"Created"'],
    '"SiteTree"',
    ['"ParentID" = 0']
);

$list = SQLQueryList::create($query);
```

Use it like any `SS_List`:

```
// Count without loading all rows
$total = $list->count();

// Get first record only (single row query)
$first = $list->first();

// Iterate (executes query and yields each row as ArrayData)
foreach ($list as $row) {
    echo $row->Title;
}

// Or get a plain array of ArrayData
$rows = $list->toArray();
```

In a controller, pass it to the template:

```
public function getReportList()
{
    $query = SQLSelect::create(
        ['"Name"', '"Total"', '"OrderCount"'],
        '"CustomerReport"',  // e.g. a view or custom table
        ['"Total" > 100']
    );
    return new SQLQueryList($query);
}
```

Template:

```

    $Name — $Total (orders: $OrderCount)

```

---

Custom row objects
------------------

[](#custom-row-objects)

By default each row is an `ArrayData`. To use your own objects (e.g. DTOs or custom models), set an output closure:

```
$list = new SQLQueryList($query);
$list->setOutputClosure(function ($row) {
    return MyReportRow::create($row);
});
```

Now `first()`, `find()`, `toArray()`, and iteration return instances of `MyReportRow` instead of `ArrayData`.

---

Sorting and limiting
--------------------

[](#sorting-and-limiting)

`sort()`, `limit()`, and `where()` modify the underlying query and return the same list instance (fluent style):

```
$query = SQLSelect::create('*', '"Orders"');
$list = new SQLQueryList($query);

// Sort by a column (ASC by default)
$list->sort('"Created"');
// Or specify direction
$list->sort('"Total"', 'DESC');
// Or multiple columns
$list->sort(['"Status"' => 'ASC', '"Created"' => 'DESC']);

// Limit and offset (e.g. pagination)
$list->limit(10, 20);  // 10 rows, skip first 20

// Add extra WHERE conditions
$list->where('"Status" = \'Paid\'');
```

Then iterate or pass to templates as usual.

---

Finding a row by column value
-----------------------------

[](#finding-a-row-by-column-value)

Use `find()` to get one row by a column value (uses a single-row query):

```
$list = new SQLQueryList($query);
$row = $list->find('ID', 123);
if ($row) {
    return $row->Title;
}
```

---

Debugging the query
-------------------

[](#debugging-the-query)

To see the underlying SQL:

```
$sql = $list->sql();
```

---

API summary
-----------

[](#api-summary)

Method / behaviourSupported`count()`Yes – uses SQL `COUNT``first()`Yes – uses `LIMIT 1``last()`Yes – uses `lastRow()` query`find($key, $value)`Yes`map($keyField, $titleField)`Yes – returns a `Map``column($colName)`Yes`columnUnique($colName)`Yes`toArray()`Yes`getIterator()` / foreachYes`sort(...)`Yes`limit($limit, $offset)`Yes`where($filter)`Yes`sql()`Yes – returns SQL string`setOutputClosure(Closure)`Yes – custom row objects`add()`, `remove()`No – read-only list`filter()`, `exclude()`No – use `where()` or build into `SQLSelect``offsetGet` / `[]`No---

Requirements
------------

[](#requirements)

- PHP ^8.1
- SilverStripe Framework ^6

License
-------

[](#license)

BSD-3-Clause

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance85

Actively maintained with recent releases

Popularity31

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~523 days

Recently: every ~330 days

Total

9

Last Release

75d ago

Major Versions

1.x-dev → 2.x-dev2022-07-19

2.1.0 → 3.0.02023-09-14

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1356335?v=4)[Jeremy Shipman](/maintainers/jedateach)[@jedateach](https://github.com/jedateach)

---

Top Contributors

[![wilr](https://avatars.githubusercontent.com/u/101629?v=4)](https://github.com/wilr "wilr (8 commits)")[![jedateach](https://avatars.githubusercontent.com/u/1356335?v=4)](https://github.com/jedateach "jedateach (7 commits)")[![bummzack](https://avatars.githubusercontent.com/u/1006185?v=4)](https://github.com/bummzack "bummzack (3 commits)")[![elliot-sawyer](https://avatars.githubusercontent.com/u/354793?v=4)](https://github.com/elliot-sawyer "elliot-sawyer (2 commits)")[![fspringveldt](https://avatars.githubusercontent.com/u/10938392?v=4)](https://github.com/fspringveldt "fspringveldt (1 commits)")[![BettinaMaria98](https://avatars.githubusercontent.com/u/50010683?v=4)](https://github.com/BettinaMaria98 "BettinaMaria98 (1 commits)")[![xini](https://avatars.githubusercontent.com/u/1152403?v=4)](https://github.com/xini "xini (1 commits)")

---

Tags

silverstripequerylist

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/burnbright-silverstripe-sqlquerylist/health.svg)

```
[![Health](https://phpackages.com/badges/burnbright-silverstripe-sqlquerylist/health.svg)](https://phpackages.com/packages/burnbright-silverstripe-sqlquerylist)
```

###  Alternatives

[silverstripe/cms

The SilverStripe Content Management System

5163.4M1.3k](/packages/silverstripe-cms)[silverstripe/admin

SilverStripe admin interface

262.6M325](/packages/silverstripe-admin)[silverstripe/silverstripe-omnipay

SilverStripe Omnipay Payment Module

38106.0k15](/packages/silverstripe-silverstripe-omnipay)[silverleague/ideannotator

Generate PHP DocBlock annotations for DataObject and DataExtension databasefields and relation methods

4768.0k43](/packages/silverleague-ideannotator)[phptek/jsontext

JSON storage, querying and modification.

2222.2k2](/packages/phptek-jsontext)

PHPackages © 2026

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