, (*1)
Blueprint Query Compiler
Blueprint is an extended query builder that allows you to define, reuse, and override chunks of query code at will., (*2)
Install via Composer
composer require sypherlev/blueprint
, (*3)
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., (*4)
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., (*5)
-
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., (*6)
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., (*7)
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., (*8)
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., (*9)
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 or RedBean instead., (*10)