How to use the translators.crate.CrateTranslatorInstance function in translators

To help you get started, we’ve selected a few translators examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github smartsdk / ngsi-timeseries-api / src / reporter / health.py View on Github external
def check_crate():
    """
    crateDB is the default backend of QuantumLeap, so it is required by
    default.
    """
    from translators.crate import CrateTranslatorInstance
    with CrateTranslatorInstance() as trans:
        crate_health = trans.get_health()
        return crate_health
github smartsdk / ngsi-timeseries-api / src / translators / factory.py View on Github external
def translator_for(fiware_service: str):
    backend = lookup_backend(fiware_service)
    backend = backend.strip().lower() if backend is not None else ''

    if backend == CRATE_BACKEND:
        translator = CrateTranslatorInstance()
        selected = CRATE_BACKEND
    elif backend == TIMESCALE_BACKEND:
        translator = postgres_translator_instance()
        selected = TIMESCALE_BACKEND
    else:
        translator = CrateTranslatorInstance()
        selected = CRATE_BACKEND

    log().info(
        f"Backend selected for tenant '{fiware_service}' is: {selected}")
    return translator
github smartsdk / ngsi-timeseries-api / src / reporter / delete.py View on Github external
def delete_entity(entity_id, type_=None, from_date=None, to_date=None):
    fiware_s = request.headers.get('fiware-service', None)
    fiware_sp = request.headers.get('fiware-servicepath', None)

    try:
        with crate.CrateTranslatorInstance() as trans:
            deleted = trans.delete_entity(entity_id=entity_id,
                                          entity_type=type_,
                                          from_date=from_date,
                                          to_date=to_date,
                                          fiware_service=fiware_s,
                                          fiware_servicepath=fiware_sp,)
    except AmbiguousNGSIIdError as e:
        return {
            "error": "AmbiguousNGSIIdError",
            "description": str(e)
        }, 409

    if deleted == 0:
        r = {
            "error": "Not Found",
            "description": "No records were found for such query."
github smartsdk / ngsi-timeseries-api / src / reporter / delete.py View on Github external
def delete_entities(entity_type, from_date=None, to_date=None):
    fiware_s = request.headers.get('fiware-service', None)
    fiware_sp = request.headers.get('fiware-servicepath', None)

    with crate.CrateTranslatorInstance() as trans:
        deleted = trans.delete_entities(entity_type=entity_type,
                                        from_date=from_date,
                                        to_date=to_date,
                                        fiware_service=fiware_s,
                                        fiware_servicepath=fiware_sp,)
        if deleted == 0:
            r = {
                "error": "Not Found",
                "description": "No records were found for such query."
            }
            return r, 404

        if deleted > 0:
            return '{} records successfully deleted.'.format(deleted), 204