def METHOD_NAME(context, dbname):
    """ Connect to the given database and return the connection
        object as a context manager that automatically closes.
        Note that the connection does not commit automatically.
    """
    if psycopg.__version__.startswith('2'):
        conn = psycopg.connect(dbname=dbname)
        conn.autocommit = True
        return closing(conn)
    return psycopg.connect(dbname=dbname, autocommit=True)