Return a list of all mappings from the given kb, ordered by key.

    If key given, give only those with left side (mapFrom) = key.
    If value given, give only those with right side (mapTo) = value.

    :param kb_name: knowledge base name. if "", return all
    :param sortby: the sorting criteria ('from' or 'to')
    :param key: return only entries where key matches this
    :param value: return only entries where value matches this
    :param limit: return only X number of entries
    :return: list of knowledge converted in dictionary

def get_kb_mappings(kb_name="", key="", value="", match_type="s", sortby="to",
                    limit=None):
    """Return a list of all mappings from the given kb, ordered by key.

    If key given, give only those with left side (mapFrom) = key.
    If value given, give only those with right side (mapTo) = value.

    :param kb_name: knowledge base name. if "", return all
    :param sortby: the sorting criteria ('from' or 'to')
    :param key: return only entries where key matches this
    :param value: return only entries where value matches this
    :param limit: return only X number of entries
    :return: list of knowledge converted in dictionary
    """
    # query
    query = db.session.query(models.KnwKBRVAL).join(models.KnwKB)
    # filter
    if kb_name:
        query = query.filter(models.KnwKB.name == kb_name)
    if len(key) > 0:
        if match_type == "s":
            key = "%"+key+"%"
    else:
        key = '%'
    if len(value) > 0:
        if match_type == "s":
            value = "%"+value+"%"
    else:
        value = '%'
    query = query.filter(
        models.KnwKBRVAL.m_key.like(key),
        models.KnwKBRVAL.m_value.like(value))
    # order by
    if sortby == "from":
        query = query.order_by(models.KnwKBRVAL.m_key)
    else:
        query = query.order_by(models.KnwKBRVAL.m_value)
    if limit:
        query = query.limit(limit)
    # return results
    return [kbv.to_dict() for (kbv) in query.all()]