def set_connection(connection=defaults.sqlalchemy_connection_string_default):
    """Set the connection string for sqlalchemy and write it to the config file.

    .. code-block:: python

        import pyhgnc
        pyhgnc.set_connection('mysql+pymysql://{user}:{passwd}@{host}/{db}?charset={charset}')


    .. hint::

        valid connection strings

        - mysql+pymysql://user:passwd@localhost/database?charset=utf8

        - postgresql://scott:tiger@localhost/mydatabase

        - mssql+pyodbc://user:passwd@database

        - oracle://user:passwd@127.0.0.1:1521/database

        - Linux: sqlite:////absolute/path/to/database.db

        - Windows: sqlite:///C:\path\to\database.db



    :param str connection: sqlalchemy connection string
    """
    config_path = defaults.config_file_path
    config = RawConfigParser()

    if not os.path.exists(config_path):
        with open(config_path, 'w') as config_file:
            config['database'] = {'sqlalchemy_connection_string': connection}
            config.write(config_file)
            log.info('create configuration file {}'.format(config_path))
    else:
        config.read(config_path)
        config.set('database', 'sqlalchemy_connection_string', connection)
        with open(config_path, 'w') as configfile:
            config.write(configfile)
Set the connection string for sqlalchemy and write it to the config file.

    .. code-block:: python

        import pyhgnc
        pyhgnc.set_connection('mysql+pymysql://{user}:{passwd}@{host}/{db}?charset={charset}')


    .. hint::

        valid connection strings

        - mysql+pymysql://user:passwd@localhost/database?charset=utf8

        - postgresql://scott:tiger@localhost/mydatabase

        - mssql+pyodbc://user:passwd@database

        - oracle://user:passwd@127.0.0.1:1521/database

        - Linux: sqlite:////absolute/path/to/database.db

        - Windows: sqlite:///C:\path\to\database.db



    :param str connection: sqlalchemy connection string