2017 © Pedro Peláez
 

silverstripe-module silverstripe-querybuilder

Builds complex and composable queries to retrieve ArrayLists in SilverStripe

image

heyday/silverstripe-querybuilder

Builds complex and composable queries to retrieve ArrayLists in SilverStripe

  • Tuesday, March 29, 2016
  • by heyday
  • Repository
  • 24 Watchers
  • 5 Stars
  • 1,055 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

SilverStripe Query Builder

Provides a way to create queries that are flexible and reusable in SilverStripe. A lot like Search Filters., (*1)

Installation (with composer)

Installing from composer is easy,, (*2)

Create or edit a composer.json file in the root of your SilverStripe project, and make sure the following is present., (*3)

{
    "require": {
        "heyday/silverstripe-querybuilder": "1.2.*"
    }
}

After completing this step, navigate in Terminal or similar to the SilverStripe root directory and run composer install or composer update depending on whether or not you have composer already in use., (*4)

Overview

Query builder is a wrapper around the SQLQuery object, providing two ways to modify the SQLQuery object:, (*5)

  • Heyday\QueryBuilder\Interfaces\QueryModifierInterface
  • Closure with function signiture SQLQuery $query, array $data, QueryBuilderInterface $queryBuilder

Usage

Implementing QueryModifierInterface

This is a very general modifier, modifiers you build might be more specific to your model., (*6)

use Heyday\QueryBuilder\Interfaces\QueryBuilderInterface;
use Heyday\QueryBuilder\Interfaces\QueryModifierInterface;

class LikeModifier extends QueryModifierInterface
{
    protected $column;
    public function __construct($column)
    {
        $this->column = $column;
    }
    public function modify(\SQLQuery $query, array $data, QueryBuilderInterface $queryBuilder)
    {
        if (isset($data['search']) && $data['search']) {
            $query->addWhere("{$this->column} LIKE '%{$data['search']}%'");
        }
    }
}

Using a modifier with QueryBuilder

use Heyday\QueryBuilder\QueryBuilder;

$qb = new QueryBuilder(
    'SiteTree',
    [new LikeModifier('SiteTree.Title')],
    ['search' => $request->getVar('q')]
);

foreach ($qb as $page) {
    // Do something with page
}

License

SilverStripe Query Builder is licensed under an MIT license, (*7)

The Versions

29/03 2016

dev-master

9999999-dev

Builds complex and composable queries to retrieve ArrayLists in SilverStripe

  Sources   Download

MIT

The Requires

 

by Glenn Bautista

29/03 2016

1.3.1

1.3.1.0

Builds complex and composable queries to retrieve ArrayLists in SilverStripe

  Sources   Download

MIT

The Requires

 

by Glenn Bautista

26/02 2016

1.3.0

1.3.0.0

Builds complex and composable queries to retrieve ArrayLists in SilverStripe

  Sources   Download

MIT

The Requires

 

by Glenn Bautista

08/09 2014

0.1.x-dev

0.1.9999999.9999999-dev

Builds complex and composable queries to retrieve ArrayLists in SilverStripe

  Sources   Download

MIT

The Requires

 

by Glenn Bautista

08/09 2014

1.2.0

1.2.0.0

Builds complex and composable queries to retrieve ArrayLists in SilverStripe

  Sources   Download

The Requires

 

by Glenn Bautista

02/09 2014

1.1.0

1.1.0.0

Builds complex and composable queries to retrieve ArrayLists in SilverStripe

  Sources   Download

The Requires

 

by Glenn Bautista

09/05 2014

1.0.0

1.0.0.0

Builds complex and composable queries to retrieve ArrayLists in SilverStripe

  Sources   Download

The Requires

 

by Glenn Bautista