PHPackages                             markjaquith/wherewithal - 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. [Database &amp; ORM](/categories/database)
4. /
5. markjaquith/wherewithal

ActiveLibrary[Database &amp; ORM](/categories/database)

markjaquith/wherewithal
=======================

Given constraints, parses a string of conditions into a valid MySQL WHERE clause

0.1.1(5y ago)15[1 issues](https://github.com/markjaquith/Wherewithal/issues)MITPHPPHP ^7.4

Since Mar 9Pushed 5y ago1 watchersCompare

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

READMEChangelogDependencies (2)Versions (4)Used By (0)

Wherewithal
===========

[](#wherewithal)

Given constraints, parses a string of conditions into a valid MySQL WHERE clause

[![Tests](https://github.com/markjaquith/Wherewithal/actions/workflows/ci.yml/badge.svg)](https://github.com/markjaquith/Wherewithal/actions/workflows/ci.yml/badge.svg)

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

[](#installation)

`composer require markjaquith/wherewithal`

Usage
-----

[](#usage)

```
use MarkJaquith\Wherewithal\{Parser, Config};

$config = (new Config)
	->addOperators('', '=', '=', '/') // Or add a subset.
	->addColumn('column_name', 'column_alias1', 'column_alias2')
	->addColumn('quantity')
	->addColumn('price', 'cost');

$parser = new Parser($config);

$structure = $parser->parse('quantity > 5 and (price < 3.00 or column_alias2 = 10'));

$structure->toString();
/*
  string(57) "quantity > ? and ( price < ? or price / column_name = ? )"
*/

$structure->getBindings()]);
/*
  array(3) {
    [0]=>
    string(1) "5"
    [1]=>
    string(4) "3.00"
    [2]=>
    string(2) "10"
  }
*/
```

You can also map simple column names to complex expressions like so:

```
$structure->mapColumns(function($col) {
	return [
		'column_name' => '`some_long_table_name`.`long_column_name`',
	]($col) ?? $col;
})->toString();
/*
	string(92) "(`some_long_table_name`.`long_column_name`) > ? and ( price < ? or price / column_name = ? )"
*/
```

Columns that you don't put in the config will be assumed to be values. Values always use the placeholder token `?`.

You should combine the resulting `WHERE` (or `HAVING`) clause using your database layer. Here's how you'd do it in Laravel:

```
$orders = DB::table('orders')
	->whereRaw($structure->toString(), $structure->getBindings())
  ->get();
```

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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

Total

2

Last Release

1887d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8f8b8e6fda805be79ffb56ec233143dc8b60a2bdc91ec1d68836388f5f2712e7?d=identicon)[markjaquith](/maintainers/markjaquith)

---

Top Contributors

[![markjaquith](https://avatars.githubusercontent.com/u/353790?v=4)](https://github.com/markjaquith "markjaquith (37 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/markjaquith-wherewithal/health.svg)

```
[![Health](https://phpackages.com/badges/markjaquith-wherewithal/health.svg)](https://phpackages.com/packages/markjaquith-wherewithal)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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