Download the PHP package girgias/query-builder without Composer
On this page you can find all versions of the php package girgias/query-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download girgias/query-builder
More information about girgias/query-builder
Files in girgias/query-builder
Package query-builder
Short Description A library to build valid SQL queries
License MIT
Informations about the package query-builder
SQL Query Builder
A fluent SQL Query Builder which ONLY builds a valid SQL query with the SQL clauses it has been asked to provide.
Installing
Features
This Query Builder can build a variety of SQL queries which are database agnostic as it uses the ANSI standardized syntax.
Every sort of query has its own class which extends from the base Query
class,
They all have the same constructor signature which requires the table name
on which to execute the query.
To build a SELECT query with table join use the SelectJoin
class.
An example can be seen below on how to use this class.
It is possible to directly provide scalar values to WHERE clauses and while binding a field. It is also possible to specify the named parameter against which the value will be bounded. In case no named parameter has been provided a random one will be generated.
To retrieve the named parameters with their associated values use the getParameters
method which will return an associative array parameter => value
.
Examples
A basic SELECT
query:
Will output:
A more complex SELECT
query:
Will output:
An example with the whereOr
method:
Will output:
UPDATE
query example:
Will output:
A SELECT
query with an INNER JOIN
:
Will output:
Future scope
Possible features that will be added to this library
- WHERE subqueries
Contributing
If you found an invalid SQL name which DOESN'T throw a Runtime exception
or a valid SQL name which does please add a test case into the
tests/CheckSqlNamesTest.php
file.
If you found an example where this library returns an invalid SQL query
please add (or fix) a test case in the relevant Query test case or if it's
a general error please use the tests/QueryTest
file.
If a RunTime exception should be thrown please add a test in the relevant test file
or if it is specific to SELECT
Query please add a test in the
tests/SelectThrowExceptionsTest.php
file.
If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.
Notes
When contributing please assure that Psalm runs without error and all unit tests pass. Moreover if you add functionality please add corresponding unit tests to cover at least 90% of your code and that these tests cover any edge cases if they exist.
Links
- Repository: https://github.com/girgias/query-builder/
- Issue tracker: https://github.com/girgias/query-builder/issues
- In case of sensitive bugs like security vulnerabilities, please contact [email protected] directly instead of using the issue tracker.
Licensing
The code in this project is licensed under MIT license.