grizz-it / dbal-sql
Database abstraction layer package implementing SQL operations
Requires
- php: ^8.0
- grizz-it/dbal: ^1.0
- grizz-it/enum: ^1.1
Requires (Dev)
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.5
This package is auto-updated.
Last update: 2024-10-29 06:30:57 UTC
README
GrizzIT DBAL SQL
GrizzIT DBAL SQL provides a SQL implementation for GrizzIT DBAL. This package only implements the query assembly part.
Installation
To install the package run the following command:
composer require grizz-it/dbal-sql
Usage
Using filters
Some queries accept filters. Filters are used to narrow down the amount of
returned results. These filters are based on the QueryFilterInterface
from the
grizz-it/dbal
package.
Filters can be grouped in the QueryFilterGroup
object. All filters inside this
group are separated by an AND statement. If a query object accepts multiple filter
groups, the filter groups will be separated by an OR statement.
- QueryFilterGroup: The base filter object expected by most queries.
Filters can be added to the group after instantiation:
use GrizzIt\Dbal\Sql\Component\Filter\QueryFilterGroup; use GrizzIt\Dbal\Sql\Component\Filter\ComparatorFilter; use GrizzIt\Dbal\Sql\Common\ComparatorEnum; // Create the filter group $filterGroup = new QueryFilterGroup; //Create the filter "column='value'" $filter = new ComparatorFilter( 'column', 'value', ComparatorEnum::EQ() ); //Add the filter $filterGroup->addFilter($filter);
- ComparatorFilter: Compare a column to a value with a standard comparator.
- ExistsFilter: Adds an EXISTS statement with a sub-query as a filter.
- QueryInFilter: Connects a default comparator with a sub-query as a filter.
- QueryOperatorFilter: Create a ANY or ALL filter in combination with a comparator for a sub-query.
- RelationalComparatorFilter: Creates
a direct value injected filter. This filter does not use a parameter, but
operates similar to the
ComparatorFilter
.
Creating queries
Queries are created by instantiating and configuring and object, before passing it to the connection.
Traits
Some queries have shared logic and thus implement common traits.
- FilterableQueryTrait: This trait is implemented by queries that support filters.
- JoinableQueryTrait: This trait is implemented by queries that support joining multiple tables in a single query.
- PageableQueryTrait: This trait is
implemented by queries that support paging (
LIMIT
with(out) anOFFSET
). - SortableQueryTrait: This trait is implemented by queries that support sorting.
Enums
Some options and queries have a limitation in the options that can be passed to the object. Enums are used for this.
- ColumnAttributeEnum
- ColumnDefaultEnum
- ColumnTypeEnum
- ComparatorEnum
- IndexTypeEnum
- OperatorEnum
- ShowTypeEnum
- UnionEnum
Queries
The queries are sorted by their affecting goal. There are also a few standard queries which don't fit in any category.
- BatchQuery: Joins multiple queries for a single line execution.
- RawQuery: If none of the query object fit the bill, this object can be used to execute a custom query.
Context
Data
Database
Table
- AbstractTableQuery: Forms the base for the other table queries.
- AlterTableQuery
- CreateTableQuery
- DropTableQuery
Column operations are defined through:
View
Index
Change log
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
MIT License
Copyright (c) GrizzIT
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.