Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nilportugues/php-sql-query-builder
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.1.1
Choose a base ref
...
head repository: nilportugues/php-sql-query-builder
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Nov 2, 2015

  1. Update composer.json

    nilportugues committed Nov 2, 2015
    Copy the full SHA
    e3d8c7c View commit details

Commits on Nov 16, 2015

  1. added where::asLiteral

    Malte Riesch committed Nov 16, 2015
    Copy the full SHA
    65ae980 View commit details
  2. Merge pull request #68 from malteriesch/master

    added where::asLiteral
    nilportugues committed Nov 16, 2015
    Copy the full SHA
    cf7fc7b View commit details

Commits on Nov 17, 2015

  1. Copy the full SHA
    916376b View commit details

Commits on Dec 2, 2015

  1. Copy the full SHA
    3dca30b View commit details

Commits on Dec 15, 2015

  1. Update .travis.yml

    nilportugues committed Dec 15, 2015
    Copy the full SHA
    8f8902d View commit details

Commits on Dec 21, 2015

  1. Update README.md

    nilportugues committed Dec 21, 2015
    Copy the full SHA
    3bf594a View commit details
  2. Update README.md

    nilportugues committed Dec 21, 2015
    Copy the full SHA
    4d9dc25 View commit details

Commits on Feb 4, 2016

  1. Update README.md

    nilportugues committed Feb 4, 2016
    Copy the full SHA
    92f1990 View commit details
  2. Compatibility for PgSQL

    nilportugues committed Feb 4, 2016
    Copy the full SHA
    e417995 View commit details
  3. Fix for postgres

    Nil Portugues Caldero committed Feb 4, 2016
    Copy the full SHA
    41a192c View commit details

Commits on Feb 8, 2016

  1. AND NOT and OR NOT

    nilportugues committed Feb 8, 2016
    Copy the full SHA
    01de3cf View commit details
  2. NOT BETWEEN

    nilportugues committed Feb 8, 2016
    Copy the full SHA
    ff624c4 View commit details
  3. Update .gitignore

    nilportugues committed Feb 8, 2016
    Copy the full SHA
    b6af3ae View commit details

Commits on Mar 6, 2016

  1. Update README.md

    nilportugues committed Mar 6, 2016
    Copy the full SHA
    23afc1e View commit details

Commits on May 6, 2016

  1. select orderby logic has changed

    Stanisław Śledziona committed May 6, 2016
    Copy the full SHA
    8df6531 View commit details

Commits on May 8, 2016

  1. Merge pull request #75 from qlarin/orderby

    select orderby logic changes
    nilportugues committed May 8, 2016
    Copy the full SHA
    877d54f View commit details

Commits on May 28, 2017

  1. Allows writing "0" to row

    Resolves issue #82.
    marcusirgens authored May 28, 2017
    Copy the full SHA
    3464371 View commit details

Commits on Jun 21, 2017

  1. Accept Column object through setColumns.

    Select->setColumns was limited to accept string... having it accept Column type object
    extends ability to add complex functions or manipulations.
    prasad83 authored Jun 21, 2017
    Copy the full SHA
    4b2fc1d View commit details
  2. Support for specifying column in condition.

    Nice to have ability to passing on instance of Column as part of condition.
    Helpful to build complex query.
    
    Example:
    ```
    where()->equals( new Column("aCol", "tmpTable"), 1);
    ```
    prasad83 authored Jun 21, 2017
    Copy the full SHA
    13fd053 View commit details
  3. Merge pull request #86 from prasad83/master

    Accept Column object through setColumns.
    nilportugues authored Jun 21, 2017
    Copy the full SHA
    a5f6c98 View commit details
  4. Merge pull request #84 from marcusirgens/patch-1

    Allows writing "0" to row
    nilportugues authored Jun 21, 2017
    Copy the full SHA
    4decdb5 View commit details

Commits on Mar 27, 2018

  1. fix the where clause issue

    mmuhasan committed Mar 27, 2018
    Copy the full SHA
    4cf4569 View commit details
  2. fix the where clause issue

    mmuhasan committed Mar 27, 2018
    Copy the full SHA
    e0b405f View commit details
  3. Copy the full SHA
    7a1275f View commit details

Commits on Jul 19, 2018

  1. Merge pull request #96 from mmuhasan/dev-where-bug-fix

    Fix the where clause issue to solve issue #73
    nilportugues authored Jul 19, 2018
    Copy the full SHA
    a941d33 View commit details

Commits on Aug 15, 2018

  1. Allow custom self column in join

    The current `JoinQuery::addJoin()` method does not allow for a
    custom `Column`. Below is an example of the use case for this
    change:
    
    ```php
    $query = new Select();
    
    $query
      ->setTable('company')
      ->setColumns([
        'company_id' => 'id',
        'name' => 'name',
      ])
      ->join(
        'field_company_code',
        'id',
        'entity_id',
      )
      ->join(
        'company_codes',
        new Column('target_id', 'field_company_code'),
        new Column('id', 'company_codes'),
        ['code' => 'code']
      );
    ```
    
    This query structure is common in Drupal when selecting values from
    fields on entities that reference other entities through the Field
    and Entity API.
    nathandentzau committed Aug 15, 2018
    Copy the full SHA
    2c2b3ab View commit details

Commits on Aug 20, 2018

  1. Merge pull request #100 from nathandentzau/nathandentzau/join-custom-…

    …self-column
    
    Allow custom self column in join
    nilportugues authored Aug 20, 2018
    Copy the full SHA
    277e87a View commit details

Commits on Feb 4, 2019

  1. Copy the full SHA
    2056f9e View commit details

Commits on Feb 5, 2019

  1. Merge pull request #104 from Sevavietl/master

    Do not reset placeholders in set writers
    nilportugues authored Feb 5, 2019
    Copy the full SHA
    8991871 View commit details

Commits on Nov 5, 2019

  1. add setWhere method

    aviggngyv committed Nov 5, 2019
    Copy the full SHA
    2aa0f1f View commit details

Commits on Mar 5, 2020

  1. Copy the full SHA
    c81d63d View commit details

Commits on Apr 7, 2020

  1. Merge pull request #113 from makeey/master

    Do not filter values in AbstractCreationalQuery
    nilportugues authored Apr 7, 2020
    Copy the full SHA
    b00877e View commit details
  2. Merge pull request #112 from hunteryun/master

    add setWhere method
    nilportugues authored Apr 7, 2020
    Copy the full SHA
    889e9e7 View commit details
  3. Copy the full SHA
    cc34010 View commit details

Commits on Jan 3, 2025

  1. Create diagram.svg

    nilportugues authored Jan 3, 2025
    Copy the full SHA
    8f340cf View commit details
  2. Update README.md

    nilportugues authored Jan 3, 2025
    Copy the full SHA
    d1a9d52 View commit details
  3. Merge pull request #131 from nilportugues/svg-diagram

    Add diagram.svg to readme
    nilportugues authored Jan 3, 2025
    Copy the full SHA
    ca6e9dd View commit details
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.idea/
build/
vendor/
bin/
14 changes: 10 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
language: php
php:
- "5.5"
- "5.6"
- "7.0"
- "hhvm"

- "7.1"
- "7.2"
- "7.3"
- "7.4"

before_script:
- composer install

@@ -13,4 +15,8 @@ script:

matrix:
allow_failures:
- php: "hhvm"
- php: "hhvm"
branches:
only:
- master

13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## Unreleased

### Added

- Added parentQuery field to Select Object
- New test for orderBy method in Select Class

### Altered

- Changed orderBy method logic in Select Class. Now every select query has access to his parent object. You can manipulate sequence of your orderBy clause.

## 1.0.2 - TBA

### Added
@@ -27,4 +38,4 @@

## 0.0.5-alpha - 2014-07-01

- Initial release
- Initial release
87 changes: 52 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
SQL Query Builder
=================

[![Build Status](https://travis-ci.org/nilportugues/sql-query-builder.svg)](https://travis-ci.org/nilportugues/sql-query-builder) [![Coverage Status](https://img.shields.io/coveralls/nilportugues/sql-query-builder.svg)](https://coveralls.io/r/nilportugues/sql-query-builder) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/nilportugues/sql-query-builder/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/nilportugues/sql-query-builder/?branch=master) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/89ec1003-4227-43a2-8432-67a9fc2d3ba3/mini.png)](https://insight.sensiolabs.com/projects/89ec1003-4227-43a2-8432-67a9fc2d3ba3) [![Latest Stable Version](https://poser.pugx.org/nilportugues/sql-query-builder/v/stable)](https://packagist.org/packages/nilportugues/sql-query-builder) [![Total Downloads](https://poser.pugx.org/nilportugues/sql-query-builder/downloads)](https://packagist.org/packages/nilportugues/sql-query-builder) [![License](https://poser.pugx.org/nilportugues/sql-query-builder/license)](https://packagist.org/packages/nilportugues/sql-query-builder)
[![Build Status](https://travis-ci.org/nilportugues/php-sql-query-builder.svg)](https://travis-ci.org/nilportugues/php-sql-query-builder) [![Coverage Status](https://img.shields.io/coveralls/nilportugues/sql-query-builder.svg)](https://coveralls.io/r/nilportugues/sql-query-builder) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/nilportugues/sql-query-builder/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/nilportugues/sql-query-builder/?branch=master) [![Latest Stable Version](https://poser.pugx.org/nilportugues/sql-query-builder/v/stable)](https://packagist.org/packages/nilportugues/sql-query-builder) [![Total Downloads](https://poser.pugx.org/nilportugues/sql-query-builder/downloads)](https://packagist.org/packages/nilportugues/sql-query-builder) [![License](https://poser.pugx.org/nilportugues/sql-query-builder/license)](https://packagist.org/packages/nilportugues/sql-query-builder)
[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://paypal.me/nilportugues)

An elegant lightweight and efficient SQL Query Builder with fluid interface SQL syntax supporting bindings and complicated query generation. **Works without establishing a connection to the database.**

An elegant lightweight and efficient SQL Query Builder with fluid interface SQL syntax supporting bindings and complicated query generation.
<a name="index_block"></a>

* [1. Installation](#block1)
@@ -61,6 +63,8 @@ php composer.phar require nilportugues/sql-query-builder

The SQL Query Builder allows to generate complex SQL queries standard using the `SQL-2003` dialect (default) and the `MySQL` dialect, that extends the `SQL-2003` dialect.

<img src="./diagram.svg" />

<a name="block2.1"></a>
### 2.1. Generic Builder [](#index_block)
The Generic Query Builder is the default builder for this class and writes standard SQL-2003.
@@ -206,7 +210,8 @@ $query = $builder->select()
])
->where()
->greaterThan('user_id', 5)
->notLike('username', 'John');
->notLike('username', 'John')
->end();

echo $builder->writeFormatted($query);
```
@@ -240,7 +245,8 @@ $query = $builder->select()
->equals('user_id', 2)
->subWhere("OR")
->lessThan($column, 10)
->greaterThan('user_id', 100);
->greaterThan('user_id', 100)
->end();

echo $builder->writeFormatted($query);
```
@@ -295,7 +301,8 @@ $query = $builder->select()
$query
->where()
->greaterThan('user_id', 5)
->notLike('username', 'John');
->notLike('username', 'John')
->end();

$query
->orderBy('created_at', OrderBy::DESC);
@@ -454,7 +461,8 @@ $query = $builder->update()
'contact' => 'contact@nilportugues.com'
])
->where()
->equals('user_id', 1);
->equals('user_id', 1)
->end();

$sql = $builder->writeFormatted($query);
$values = $builder->getValues();
@@ -493,7 +501,8 @@ $query = $builder->update()
$query
->where()
->like('username', '%N')
->between('user_id', 1, 2000);
->between('user_id', 1, 2000)
->end();

$query
->orderBy('user_id', OrderBy::ASC)
@@ -559,7 +568,8 @@ $query = $builder->delete()

$query
->where()
->equals('user_id', 100);
->equals('user_id', 100)
->end();

$query
->limit(1);
@@ -591,7 +601,8 @@ $query = $builder->delete()
$query
->where()
->like('username', '%N')
->between('user_id', 1, 2000);
->between('user_id', 1, 2000)
->end();

$query
->orderBy('user_id', OrderBy::ASC)
@@ -767,27 +778,28 @@ SELECT user_email.* FROM user_email
The following operators are available for filtering using WHERE conditionals:

```php
public function subWhere($operator = 'OR');
public function equals($column, $value);
public function compare($column, $value, $operator);
public function notEquals($column, $value);
public function greaterThan($column, $value);
public function greaterThanOrEqual($column, $value);
public function lessThan($column, $value);
public function lessThanOrEqual($column, $value);
public function like($column, $value);
public function notLike($column, $value);
public function match(array $columns, array $values);
public function matchBoolean(array $columns, array $values);
public function matchWithQueryExpansion(array $columns, array $values);
public function in($column, array $values);
public function notIn($column, array $values);
public function between($column, $a, $b);
public function isNull($column);
public function isNotNull($column);
public function exists(Select $select);
public function notExists(Select $select);
public function addBitClause($column, $value);
public function subWhere($operator = 'OR');
public function equals($column, $value);
public function notEquals($column, $value);
public function greaterThan($column, $value);
public function greaterThanOrEqual($column, $value);
public function lessThan($column, $value);
public function lessThanOrEqual($column, $value);
public function like($column, $value);
public function notLike($column, $value);
public function match(array $columns, array $values);
public function matchBoolean(array $columns, array $values);
public function matchWithQueryExpansion(array $columns, array $values);
public function in($column, array $values);
public function notIn($column, array $values);
public function between($column, $a, $b);
public function notBetween($column, $a, $b);
public function isNull($column);
public function isNotNull($column);
public function exists(Select $select);
public function notExists(Select $select);
public function addBitClause($column, $value);
public function asLiteral($literal);
```

<a name="block4.2"></a>
@@ -806,7 +818,8 @@ $query = $builder->select()
->setTable('user')
->where('OR')
->equals('user_id', 1)
->like('name', '%N%');
->like('name', '%N%')
->end();

$sql = $builder->writeFormatted($query);
$values = $builder->getValues();
@@ -933,7 +946,8 @@ $query = $builder->select()
->setSelectAsColumn(array('user_role' => $selectRole))
->setSelectAsColumn(array($selectRole))
->where()
->equals('user_id', 4);
->equals('user_id', 4)
->end();

$sql = $builder->writeFormatted($query);
$values = $builder->getValues();
@@ -984,7 +998,8 @@ $query = $builder->select()
->setColumns(array('user_id', 'username'))
->setValueAsColumn('10', 'priority')
->where()
->equals('user_id', 1);
->equals('user_id', 1)
->end();

$sql = $builder->writeFormatted($query);
$values = $builder->getValues();
@@ -1018,7 +1033,8 @@ $query = $builder->select()
->setColumns(array('user_id', 'username'))
->setFunctionAsColumn('MAX', array('user_id'), 'max_id')
->where()
->equals('user_id', 1);
->equals('user_id', 1)
->end();

$sql = $builder->writeFormatted($query);
$values = $builder->getValues();
@@ -1050,7 +1066,8 @@ $query = $builder->select()
->setColumns(array('user_id', 'username'))
->setFunctionAsColumn('CURRENT_TIMESTAMP', array(), 'server_time')
->where()
->equals('user_id', 1);
->equals('user_id', 1)
->end();

$sql = $builder->writeFormatted($query);
$values = $builder->getValues();
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@
"nilportugues/sql-query-formatter": "~1.2"
},
"require-dev": {
"phpunit/phpunit": "5.*",
"phpunit/phpunit": "4.*",
"fabpot/php-cs-fixer": "~1.9",
"nilportugues/php_backslasher": "~0.2"
},
Loading