<commit_before>[![Build Status](https://travis-ci.org/olajoscs/QueryBuilder.svg?branch=master)](https://travis-ci.org/olajoscs/QueryBuilder)
[![Latest Stable Version](https://poser.pugx.org/olajoscs/querybuilder/v/stable)](https://packagist.org/packages/olajoscs/querybuilder)
# QueryBuilder
A simple query builder for relational databases, currently with MySQL and PostgreSQL support. 100% of the code is unit tested.

Contains the 4 basic (CRUD) operations with transaction handling.

Minimum requirements: PHP 5.5+ with MySQL or PostgreSQL.

# Creating the connection
The Connection class extends the built-in PDO class. It is the starting point of creating statements.
Create a new instance based on the database type you are using, and give it to your DI container trait it as a singleton.
The constructor is the same as the one in the PDO class.

```php
  $myDIContainer->singleton('connection', function() {
    return new OlajosCs\QueryBuilder\MySQL\Connection($type, $host, $username, $password, $database, $options)
  });
```

# Starting from Connection
There are 4 statements (Select, Update, Insert, Delete), which have own methods to create.
All the statements has an execute method, which executes the built query, then returns the PDOStatement object.

## Transaction
Transaction can be used with a callback function. In case of any exception all changes are rollbacked.
```php
  $connection->transaction(function() use ($connection) {
    $connection->get(...);
  });
```

## Basic select syntax
The syntax of building a select statmenet is similar to do it in SQL.
```php
  $connection
    ->select(['field', 'list'])
    ->from('table_name')
    ->where('field', '=', $value)<commit_msg>Update the readme according to the new pattern<commit_after>[![Build Status](https://travis-ci.org/olajoscs/QueryBuilder.svg?branch=master)](https://travis-ci.org/olajoscs/QueryBuilder)
[![Latest Stable Version](https://poser.pugx.org/olajoscs/querybuilder/v/stable)](https://packagist.org/packages/olajoscs/querybuilder)
# QueryBuilder
A simple query builder for relational databases, currently with MySQL and PostgreSQL support. 100% of the code is unit tested.

Contains the 4 basic (CRUD) operations with transaction handling.

Minimum requirements: PHP 5.5+ with MySQL or PostgreSQL.

# Creating the connection
The Connection class extends the built-in PDO class. It is the starting point of creating statements.
Create a new instance based on the database type you are using, and give it to your DI container trait it as a singleton.
The constructor is the same as the one in the PDO class.

```php
  $myDIContainer->singleton('connection', function() {
    // Create a config object, which implements the Config interface
    $configArray = include(..);
    $config = new Config($configArray);
    
    // Create the PDO by the config object
    $pdo = new \OlajosCs\QueryBuilder\PDO($config);
    
    // Create a connection factory
    $connectionFactory = new \OlajosCs\QueryBuilder\ConnectionFactory();
    
    // Use the ConnectionFactory to create the Connection object by the PDO
    $connection = $connectionFactory->create($pdo);
    
    return $connection;
  });
```

# Starting from Connection
There are 4 statements (Select, Update, Insert, Delete), which have own methods to create.
All the statements has an execute method, which executes the built query, then returns the PDOStatement object.

## Transaction
Transaction can be used with a callback function. In case of any exception all changes are rollbacked.
```php
  $connection->transaction(function() use ($connection) {
    $connection->get(...);
  });
```

## Basic select syntax
The syntax of building a select statmenet is similar to do it in SQL.
```php
  $connection
    ->select(['field', 'list'])
    ->from('table_name')
    ->where('field', '=', $value)
{'fraction_non_alphanumeric': 0.10602910602910603, 'fraction_numerical': 0.0036382536382536385, 'mean_word_length': 4.428772919605078, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7161427', 'n_tokens_mistral': 1084, 'n_tokens_neox': 1039, 'n_words': 424}