<commit_before>Drivers
=======

Several different types of drivers are supported. Currently theese are available:

Redis Extension
---------------

Requires the installation of the pecl extension. You can add the following to your ``composer.json`` file
to make sure it is installed:

.. configuration-block::

    .. code-block:: json

        {
            "require" : {
                "ext-redis" : "~2.2"
            }
        }

    .. code-block:: php

        <?php

        use Bernard\Driver\PhpRedisDriver;

        $redis = new Redis();
        $redis->connect('127.0.0.1', 6379);
        $redis->setOption(Redis::OPT_PREFIX, 'bernard:');

        $driver = new PhpRedisDriver($redis);

Predis
------

Requires the installation of predis. Add the following to your ``composer.json`` file for this:

.. configuration-block::

    .. code-block:: json

        {
            "require" : {
                "predis/predis" : "~0.8"
            }
        }

    And then instanciate the correct driver object.

    .. code-block:: php

        <?php

        use Bernard\Driver\PredisDriver;
        use Predis\Client;

        $predis = new Client('tcp://localhost', array(
            'prefix' => 'bernard:',
        ));

        $driver = new PredisDriver($predis);<commit_msg>add documentation for doctrine driver<commit_after>Drivers
=======

Several different types of drivers are supported. Currently theese are available:

Redis Extension
---------------

Requires the installation of the pecl extension. You can add the following to your ``composer.json`` file
to make sure it is installed:

.. configuration-block::

    .. code-block:: json

        {
            "require" : {
                "ext-redis" : "~2.2"
            }
        }

    .. code-block:: php

        <?php

        use Bernard\Driver\PhpRedisDriver;

        $redis = new Redis();
        $redis->connect('127.0.0.1', 6379);
        $redis->setOption(Redis::OPT_PREFIX, 'bernard:');

        $driver = new PhpRedisDriver($redis);

Predis
------

Requires the installation of predis. Add the following to your ``composer.json`` file for this:

.. configuration-block::

    .. code-block:: json

        {
            "require" : {
                "predis/predis" : "~0.8"
            }
        }

    And then instanciate the correct driver object.

    .. code-block:: php

        <?php

        use Bernard\Driver\PredisDriver;
        use Predis\Client;

        $predis = new Client('tcp://localhost', array(
            'prefix' => 'bernard:',
        ));

        $driver = new PredisDriver($predis);

Doctrine DBAL
-------------

For small usecases or testing there is a Doctrine DBAL driver which supports all of the major
database platforms.

The driver uses transactions to make sure that a single consumer always get the message popped from the queue.

.. important::

    To use Doctrine DBAL remember to setup the correct schema.

The schema for the messages is as follows:

.. code-block:: sql

    CREATE TABLE `messages` (
        `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
        `queue` varchar(255) DEFAULT NULL,
        `message` longtext,
        PRIMARY KEY (`id`),
        KEY `queue_idx` (`queue`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8


.. configuration-block::

    .. code-block:: json

        {
            "require" : {
                "doctrine/dbal" : "~2.3"
            }
        }

    And then instanciate the correct driver object.

    .. code-block:: php

        <?php

        use Bernard\Driver\DoctrineDriver;
        use Doctrine\DBAL\DriverManager;

        $connection = DriverManager::getConnection(array(
            'dbname' => 'bernard',
            'user' => 'root',
            'password' => <PASSWORD>,
            'driver' => 'pdo_mysql',
        ));


        $driver = new DoctrineDriver($connection);
{'fraction_non_alphanumeric': 0.13018672199170125, 'fraction_numerical': 0.00933609958506224, 'mean_word_length': 1.9308510638297873, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '455920', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1080, 'n_words': 323}