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

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

lyonstahl/soql-builder
======================

SOQL builder that simplifies the process of constructing complex queries to retrieve data from Salesforce databases

1.0.3(2y ago)015.6k↓26.9%Apache-2.0PHPPHP &gt;=7.3

Since Mar 16Pushed 1y agoCompare

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

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

Salesforce SOQL Builder
=======================

[](#salesforce-soql-builder)

SOQL builder that simplifies the process of constructing complex queries to retrieve data from Salesforce databases.

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

[](#installation)

Ensure you have [composer](http://getcomposer.org) installed, then run the following command:

```
composer require lyonstahl/soql-builder

```

That will fetch the library and its dependencies inside your vendor folder. Then you need to use the relevant class, for example:

```
use LyonStahl\SoqlBuilder\SoqlBuilder;
```

Features
--------

[](#features)

- Select
- Conditionals (where)
- Conditionals for date values
- Grouped conditional statements
- Where in
- Where not in
- Limit
- Offset
- Order By

Usage
-----

[](#usage)

Builder has two entry points for comfortable static usage: `SoqlBuilder::select()` and `SoqlBuilder::from()`. Both methods return a `SoqlBuilder` instance.
In any other context, you **must** call `addSelect()` and `setFrom()` to add the "SELECT" and "FROM" statements. See examples below.

```
SoqlBuilder::select(['Id', 'Name', 'created_at'])
    ->setFrom('Account')
    ->where('Name', '=', 'Test')
    ->limit(20)
    ->orderBy('created_at', 'DESC')
    ->toSoql();
```

`> SELECT Id, Name, created_at FROM Account WHERE Name = 'Test' ORDER BY created_at DESC LIMIT 20`

```
SoqlBuilder::from('Account')
    ->addSelect(['Id', 'Name'])
    ->where('Name', '=', 'Test')
    ->orWhere('Name', '=', 'Testing')
    ->toSoql();
```

`> SELECT Id, Name FROM Account WHERE Name = 'Test' OR Name = 'Testing'`

```
SoqlBuilder::select(['Id', 'Name'])
    ->setFrom('Account')
    ->startWhere()
    ->where('Name', '=', 'Test')
    ->where('Testing__c', '=', true)
    ->endWhere()
    ->orWhere('Email__c', '=', 'test@test.com')
    ->toSoql();
```

`> SELECT Id, Name FROM Account WHERE (Name = 'Test' AND Testing__c = true) OR Email__c = 'test@test.com'`

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

[](#requirements)

- [PHP 7.3+](https://www.php.net)
- [Composer 2.0+](https://getcomposer.org)
- PHPUnit is required to run the unit tests

Running for development with Docker
-----------------------------------

[](#running-for-development-with-docker)

We have included a Dockerfile to make it easy to run the tests and debug the code. You must have Docker installed. The following commands will build the image and run the container:

1. `docker build -t lyonstahl/soql-builder --build-arg PHP_VERSION=8 .`
2. `docker run -it --rm -v ${PWD}:/var/www/soql lyonstahl/soql-builder sh`

Debugging with XDebug in VSCode
-------------------------------

[](#debugging-with-xdebug-in-vscode)

Docker image is configured with XDebug. To debug the code with VSCode, follow these steps:

1. Install the [PHP Debug extension](https://marketplace.visualstudio.com/items?itemName=xdebug.php-debug) in VSCode
2. Add a new PHP Debug configuration in VSCode:

    ```
    {
        "name": "XDebug Docker",
        "type": "php",
        "request": "launch",
        "port": 9003,
        "pathMappings": {
            "/var/www/soql/": "${workspaceRoot}/"
        }
    }

    ```
3. `docker run -it --rm -v ${PWD}:/var/www/soql --add-host host.docker.internal:host-gateway lyonstahl/soql-builder sh`
4. Start debugging in VSCode with the 'XDebug Docker' configuration.

Testing
-------

[](#testing)

This library ships with PHPUnit for development. Composer file has been configured with some scripts, run the following command to run the tests:

```
composer test

```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% 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 ~128 days

Total

4

Last Release

774d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5c62eb11675fca05cf626660aff044739bdcd80bfa3e2dab8a6afda763c219d5?d=identicon)[PAXANDDOS](/maintainers/PAXANDDOS)

---

Top Contributors

[![mihasicehcek](https://avatars.githubusercontent.com/u/10881356?v=4)](https://github.com/mihasicehcek "mihasicehcek (12 commits)")[![PAXANDDOS](https://avatars.githubusercontent.com/u/40315177?v=4)](https://github.com/PAXANDDOS "PAXANDDOS (5 commits)")[![faridkoch](https://avatars.githubusercontent.com/u/26866544?v=4)](https://github.com/faridkoch "faridkoch (1 commits)")

---

Tags

querybuildersalesforcesoql

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lyonstahl-soql-builder/health.svg)

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

###  Alternatives

[envms/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

925511.7k13](/packages/envms-fluentpdo)[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11120.2M21](/packages/anourvalar-eloquent-serialize)[lichtner/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

921274.8k6](/packages/lichtner-fluentpdo)[fpdo/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

921244.9k7](/packages/fpdo-fluentpdo)[mistic100/jquery-querybuilder

jQuery plugin for user friendly query/filter creator

1.7k54.1k2](/packages/mistic100-jquery-querybuilder)[nilportugues/sql-query-builder

An elegant lightweight and efficient SQL QueryInterface BuilderInterface supporting bindings and complicated query generation.

425239.4k6](/packages/nilportugues-sql-query-builder)

PHPackages © 2026

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