https://github.com/siriusphp/sql
Flexible query building library for PDO connections with a small API surface and auto-complete support (low cognitive load)
https://github.com/siriusphp/sql
mysql pdo pdo-php php query sql sqlite
Last synced: about 1 month ago
JSON representation
Flexible query building library for PDO connections with a small API surface and auto-complete support (low cognitive load)
- Host: GitHub
- URL: https://github.com/siriusphp/sql
- Owner: siriusphp
- License: mit
- Created: 2020-02-07T08:09:24.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-11-24T15:04:10.000Z (over 5 years ago)
- Last Synced: 2025-07-17T20:56:13.745Z (11 months ago)
- Topics: mysql, pdo, pdo-php, php, query, sql, sqlite
- Language: PHP
- Size: 74.2 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Sirius Sql
[](https://github.com/siriusphp/sql)
[](https://github.com/siriusphp/sql/releases)
[](https://github.com/siriusphp/sql/blob/master/LICENSE)
[](https://github.com/siriusphp/sql/actions)
[](https://scrutinizer-ci.com/g/siriusphp/sql/code-structure)
[](https://scrutinizer-ci.com/g/siriusphp/sql)
The `siriusphp/sql` library is designed to help you build and execute SQL simple and complex queries in a fast and safe way.
The vocabulary is as close to SQL as possible as you may see from the example below:
```php
use Atlas\Pdo\Connection;
use Sirius\Sql\Select;
use Sirius\Sql\ConditionsEnum;
$connection = Connection::new('sqlite::memory:');
$select = new Select($connection);
// find the 10 "cool" posts that are published and also retrieve the comments count
$select->distinct()
->columns('posts.*', 'COUNT(comments.id) AS comments_count')
->from('posts')
->join('LEFT', 'comments', 'comments.commentable_id = posts.id AND comments.commentable_type = %s', 'posts')
->where('posts.published_at < NOW()')
->where('posts.title', 'cool', ConditionsEnum::CONTAINS)
->groupBy('posts.id')
->limit(10);
$posts = $select->fectchAll();
```
## Links
- [documentation](http://sirius.ro/php/sirius/sql/)
- [changelog](CHANGELOG.md)
## Acknowledgements
This library is a derivative work of [atlas/query](http://atlasphp.io/cassini/query/). I made this library for 2 reasons:
- to reduce cognitive load by removing some methods and implementing other ways to achieve the same goals (eg: nested conditions)
- to optimize some operations for the most common scenarios (eg: `where($column, $str, 'does_not_contain')` vs `where($column . ' LIKE ', '%' . $str . '%')`