<commit_before>## Crate.io driver for Laravel 5

This is an Eloquent and Query builder support for Crate.io. Extends 
the original Laravel API with Crate PDO driver.

###Crate and Crate PDO

Crate is a distributed SQL Database based on Elasticsearch, Lucene 
and other goodies. See their official page on [Crate.io](https://crate.io)
for more info.  

Crate.io published a [PDO](https://github.com/crate/crate-pdo) and
[DBAL](https://github.com/crate/crate-dbal) driver for easy access to
the crate DB server.
Laravel-crate.io project uses those adapters when connecting to Crate DB.  

###Project status

Laravel-crate.io is used in our internal projects. We did a bunch of
unit tests and the driver seems ok. We use id as a caching layer in front
of our DB servers. Crate is insanely fast (Elasticsearch) and offloads our
DB servers a lot.  

Still, it's still early in development, so **if you find any bugs, please
open an issue ticket**.

###Installation

Add a require to your composer.json  :

```json
{
    "require": {
        "ratkor/laravel-crate.io": "*"
    }
}
```

and run `composer update`.

After composer downloads your package, you'll have to register this new Crate
DB provider in Laravel. Open `config/app.php` and add:

```php
'RatkoR\Crate\CrateServiceProvider',
```

to the list of `providers`.

You'll have to install crate.io server, of course. See installation
instructions on their site.


###Configuration

Open `config/database.php` and add new crate database connection (with
config values to match your setup):

```php
'crate' => array(
    'driver'   => 'crate',
    'host'     => 'localhost',
    'database' => 'doc',
    'port'     => 4200,
),
```

Next, change default database connection to `"crate"`.

```php
'default' => 'crate',
```

**Note on PDO::FETCH_CLASS**  

Crate doesn't support PDO::FETCH_CLASS so we silently change it to PDO::FETCH_ASSOC.
This happens only for Crate connections, zour normal MySQL connections will still use FETCH_CLASS.

See more about fetch types on their [github](https://github.com/crate/crate-pdo).


###What works and what doesn't

Crate.io supports many of the SQL statements, but not all of them. Be sure to 
take a look at their [site](https://crate.io/docs/stable/sql/index.html) if you're in doubt.

We're throwing an `RatkoR\Crate\NotImplementedException` for those statements that you
might wrongly try to use. We tried to cover all of them, but if we missed any
you'll get Exception from Crate DB.

Big things that are **not** supported are:  <commit_msg>Added documentation for multiple hosts config.<commit_after>## Crate.io driver for Laravel 5

This is an Eloquent and Query builder support for Crate.io. Extends 
the original Laravel API with Crate PDO driver.

###Crate and Crate PDO

Crate is a distributed SQL Database based on Elasticsearch, Lucene 
and other goodies. See their official page on [Crate.io](https://crate.io)
for more info.  

Crate.io published a [PDO](https://github.com/crate/crate-pdo) and
[DBAL](https://github.com/crate/crate-dbal) driver for easy access to
the crate DB server.
Laravel-crate.io project uses those adapters when connecting to Crate DB.  

###Project status

Laravel-crate.io is used in our internal projects. We did a bunch of
unit tests and the driver seems ok. We use id as a caching layer in front
of our DB servers. Crate is insanely fast (Elasticsearch) and offloads our
DB servers a lot.  

Still, it's still early in development, so **if you find any bugs, please
open an issue ticket**.

###Installation

Add a require to your composer.json  :

```json
{
    "require": {
        "ratkor/laravel-crate.io": "*"
    }
}
```

and run `composer update`.

After composer downloads your package, you'll have to register this new Crate
DB provider in Laravel. Open `config/app.php` and add:

```php
'RatkoR\Crate\CrateServiceProvider',
```

to the list of `providers`.

You'll have to install crate.io server, of course. See installation
instructions on their site.


###Configuration

Open `config/database.php` and add new crate database connection (with
config values to match your setup):

```php
'crate' => array(
    'driver'   => 'crate',
    'host'     => 'localhost',
    'database' => 'doc',
    'port'     => 4200,
),
```

Next, change default database connection to `"crate"`.

```php
'default' => 'crate',
```

####Configuration for multiple hosts

This driver can handle conenctions to multiple crate hosts. To use them, write
`host` config parameter as a comma delimited list of hosts. Like:

```php
'crate' => array(
    'driver'   => 'crate',
    'host'     => 'localhost,10.0.0.1,10.0.0.2',
    'database' => 'doc',
    'port'     => 4200,
),
```

The DSN created in this case looks like:
```
'crate:localhost:4200,10.0.0.1:4200,10.0.0.2:4200'
```

If you need to specify different ports, add them to the `host` param like:

```php
    'host'     => 'localhost:4201,10.0.0.1:4300,10.0.0.2',
```

which will create a DSN like:
```
'crate:localhost:4201,10.0.0.1:4300,10.0.0.2:4200'
```

**Randomization**

`crate-pdo` takes [the first host](https://github.com/crate/crate-pdo/blob/master/src/Crate/PDO/PDO.php#L87)
from list of hosts. To overcome this we randomize all hosts
so that connections to multiple crate servers are distributed. If you don't want
randomization, add a `randomHosts` parameter and set it to `false`:

```php
'crate' => array(
    'driver'   => 'crate',
    'host'     => 'localhost,10.0.0.1,10.0.0.2',
    'database' => 'doc',
    'port'     => 4200,
    'randomHosts' => false,
),
```


**Note on PDO::FETCH_CLASS**  

Crate doesn't support PDO::FETCH_CLASS so we silently change it to PDO::FETCH_ASSOC.
This happens only for Crate connections, zour normal MySQL connections will still use FETCH_CLASS.

See more about fetch types on their [github](https://github.com/crate/crate-pdo).


###What works and what doesn't

Crate.io supports many of the SQL statements, but not all of them. Be sure to 
take a look at their [site](https://crate.io/docs/stable/sql/index.html) if you're in doubt.

We're throwing an `RatkoR\Crate\NotImplementedException` for those statements that you
might wrongly try to use. We tried to cover all of them, but if we missed any
you'll get Exception from Crate DB.

Big things that are **not** supported are:  
{'fraction_non_alphanumeric': 0.11561609122584732, 'fraction_numerical': 0.016154577130186885, 'mean_word_length': 3.8576923076923078, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 11, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 10, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1476916', 'n_tokens_mistral': 2097, 'n_tokens_neox': 2027, 'n_words': 802}