async def METHOD_NAME(
    sql_query, result_name="query_result", additional_elements=None
):
    """
    Generate a JSON representation of a query result.
    Parameters
    ----------
    sql_query : str
        SQL query to stream output of
    result_name : str
        Name of the JSON item containing the rows of the result
    additional_elements : dict
        Additional JSON elements to include along with the query result
    Yields
    ------
    bytes
        Encoded lines of JSON
    """
    logger = current_app.flowapi_logger
    db_conn_pool = current_app.db_conn_pool
    prefix = "{"
    if additional_elements:
        for key, value in additional_elements.items():
            prefix += f'"{key}":{json.dumps(value)}, '
    prefix += f'"{result_name}":['
    yield prefix.encode()
    prepend = ""
    logger.debug("Starting generator.", request_id=request.request_id)
    async with db_conn_pool.acquire() as connection:
        # Configure asyncpg to encode/decode JSON values
        await connection.set_type_codec(
            "json", encoder=json.dumps, decoder=json.loads, schema="pg_catalog"
        )
        logger.debug("Connected.", request_id=request.request_id)
        async with connection.transaction():
            logger.debug("Got transaction.", request_id=request.request_id)
            logger.debug(f"Running {sql_query}", request_id=request.request_id)
            try:
                async for row in connection.cursor(sql_query):
                    yield f"{prepend}{json.dumps(dict(row.items()), number_mode=json.NM_DECIMAL, datetime_mode=json.DM_ISO8601)}".encode()
                    prepend = ", "
                logger.debug("Finishing up.", request_id=request.request_id)
                yield b"]}"
            except Exception as e:
                logger.error(e)