https://github.com/sypherlev/blueprint
DBAL package that performs data operations through applying reusable code
https://github.com/sypherlev/blueprint
database mariadb mit-license mysql pds-skeleton php7 query-builder
Last synced: about 2 months ago
JSON representation
DBAL package that performs data operations through applying reusable code
- Host: GitHub
- URL: https://github.com/sypherlev/blueprint
- Owner: sypherlev
- License: mit
- Created: 2016-10-12T16:51:38.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-07-20T15:17:48.000Z (almost 6 years ago)
- Last Synced: 2025-05-04T20:24:05.763Z (about 1 year ago)
- Topics: database, mariadb, mit-license, mysql, pds-skeleton, php7, query-builder
- Language: PHP
- Size: 162 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/php-pds/skeleton) [](https://opensource.org/licenses/MIT) [](https://travis-ci.org/sypherlev/blueprint)
# Blueprint Query Compiler
* [Setup](https://github.com/sypherlev/blueprint/blob/master/docs/Setup.md)
* [Sample](https://github.com/sypherlev/blueprint/blob/master/docs/Sample.md)
* [The Query Builder](https://github.com/sypherlev/blueprint/blob/master/docs/QueryBuilder.md)
* [Patterns](https://github.com/sypherlev/blueprint/blob/master/docs/Patterns.md)
* [Filters](https://github.com/sypherlev/blueprint/blob/master/docs/Filters.md)
* [Transformations](https://github.com/sypherlev/blueprint/blob/master/docs/Transformations.md)
Blueprint is an extended query builder that allows you to define, reuse, and override chunks of query code at will.
### Install via Composer
`composer require sypherlev/blueprint`
### Background
I found that, while building a number of large, data-driven apps, an ORM just got in the way most of the time, while a query builder meant writing lots of difficult-to-maintain, copy-pasted and possibly-insecure code. As using an ORM didn’t lend itself to what I was trying to do, I started with a query builder and set about fixing those issues instead. The end result is Blueprint.
Blueprint’s core is a fairly robust query builder that allows for most common SQL operations, and a fallback to raw SQL. Blueprint is extended with additional elements that allow for reusable, configured query sections, which cuts the amount of copy-pasting code to a minimum, and includes some built-in security out of the box.
* **Patterns**: A Pattern defines tables, columns, and joins for a query, and the primary table and its columns double as a whitelist when used with INSERT/UPDATE queries.
* **Filters**: A Filter defines additional where clauses, and the limit and orderBy clauses for a query.
* **Transformations**: A Transformation is a simple closure that modifies data going into an INSERT/UPDATE query, and modifies data coming out of a SELECT query.
Patterns, Filters and Transformations are normally defined in the constructor of a Blueprint-extending class and then used as needed in specific methods.
All queries generated by the builder use prepared statements, and there is an additional function, `raw()`, that will accept any arbitrary SQL string with or without bindings.
It currently supports MySQL/MariaDB/PostgreSQL, with an interface definition so that more can be added. The pattern/filter setup can only define whatever comes out of a single query, which means defining one-to-many or many-to-many relationships requires the use of a transformation after the initial query result to append more data as needed.
**Note: there is no functionality to create or modify tables, and I don’t intend to add any at this time.** Blueprint assumes you have a fairly solid working knowledge of SQL already, and you’ve created the schema externally or you’re working with a pre-existing database.
As it’s purpose-built for managing and processing large blocks of complex relational data, Blueprint is not recommended for basic CRUD work. Please look at [Propel](http://propelorm.org/) or [RedBean](https://redbeanphp.com/index.php) instead.