# Path: eloquent/connectors/mysql_connector.py
# class MySqlConnector(Connector):
# 
#     RESERVED_KEYWORDS = [
#         'log_queries', 'driver', 'prefix',
#         'engine', 'charset', 'collation'
#     ]
# 
#     def connect(self, config):
#         config = dict(config.items())
#         for key, value in keys_fix.items():
#             config[value] = config[key]
#             del config[key]
# 
#         config['autocommit'] = True
#         config['cursorclass'] = cursor_class
# 
#         return self.get_api().connect(**self.get_config(config))
# 
#     def get_api(self):
#         return mysql
# 
# Path: eloquent/connectors/postgres_connector.py
# class PostgresConnector(Connector):
# 
#     def connect(self, config):
#         connection = self.get_api().connect(
#             connection_factory=psycopg2.extras.DictConnection,
#             **self.get_config(config)
#         )
#         connection.autocommit = True
# 
#         return connection
# 
#     def get_api(self):
#         return psycopg2
# 
# Path: eloquent/connectors/sqlite_connector.py
# class SQLiteConnector(Connector):
# 
#     def connect(self, config):
#         connection = self.get_api().connect(**self.get_config(config))
#         connection.isolation_level = None
#         connection.row_factory = DictCursor
# 
#         return connection
# 
#     def get_api(self):
#         return sqlite3


import random
from ..exceptions import ArgumentError
from ..exceptions.connectors import UnsupportedDriver
from .mysql_connector import MySqlConnector
from .postgres_connector import PostgresConnector
from .sqlite_connector import SQLiteConnector
from ..connections import (
    MySqlConnection,
    PostgresConnection,
    SQLiteConnection
)
        return connection

    def _create_read_connection(self, config):
        read_config = self._get_read_config(config)

        return self.create_connector(read_config).connect(read_config)

    def _get_read_config(self, config):
        read_config = self._get_read_write_config(config, 'read')

        return self._merge_read_write_config(config, read_config)

    def _get_write_config(self, config):
        write_config = self._get_read_write_config(config, 'write')

        return self._merge_read_write_config(config, write_config)

    def _get_read_write_config(self, config, type):
        if config.get(type, []):
            return random.choice(config[type])

        return config[type]

    def _merge_read_write_config(self, config, merge):
        config = config.copy()
        config.update(merge)

        del config['read']
        del config['write']


# Path: eloquent/connectors/mysql_connector.py
# class MySqlConnector(Connector):
# 
#     RESERVED_KEYWORDS = [
#         'log_queries', 'driver', 'prefix',
#         'engine', 'charset', 'collation'
#     ]
# 
#     def connect(self, config):
#         config = dict(config.items())
#         for key, value in keys_fix.items():
#             config[value] = config[key]
#             del config[key]
# 
#         config['autocommit'] = True
#         config['cursorclass'] = cursor_class
# 
#         return self.get_api().connect(**self.get_config(config))
# 
#     def get_api(self):
#         return mysql
# 
# Path: eloquent/connectors/postgres_connector.py
# class PostgresConnector(Connector):
# 
#     def connect(self, config):
#         connection = self.get_api().connect(
#             connection_factory=psycopg2.extras.DictConnection,
#             **self.get_config(config)
#         )
#         connection.autocommit = True
# 
#         return connection
# 
#     def get_api(self):
#         return psycopg2
# 
# Path: eloquent/connectors/sqlite_connector.py
# class SQLiteConnector(Connector):
# 
#     def connect(self, config):
#         connection = self.get_api().connect(**self.get_config(config))
#         connection.isolation_level = None
#         connection.row_factory = DictCursor
# 
#         return connection
# 
#     def get_api(self):
#         return sqlite3


# Path: eloquent/connectors/connection_factory.py
import random
from ..exceptions import ArgumentError
from ..exceptions.connectors import UnsupportedDriver
from .mysql_connector import MySqlConnector
from .postgres_connector import PostgresConnector
from .sqlite_connector import SQLiteConnector
from ..connections import (
    MySqlConnection,
    PostgresConnection,
    SQLiteConnection
)

        return connection

    def _create_read_connection(self, config):
        read_config = self._get_read_config(config)

        return self.create_connector(read_config).connect(read_config)

    def _get_read_config(self, config):
        read_config = self._get_read_write_config(config, 'read')

        return self._merge_read_write_config(config, read_config)

    def _get_write_config(self, config):
        write_config = self._get_read_write_config(config, 'write')

        return self._merge_read_write_config(config, write_config)

    def _get_read_write_config(self, config, type):
        if config.get(type, []):
            return random.choice(config[type])

        return config[type]

    def _merge_read_write_config(self, config, merge):
        config = config.copy()
        config.update(merge)

        del config['read']
        del config['write']


        return config