Esempio n. 1
0
def table_from_ptrref(
    ptrref: irast.PointerRef,
    *,
    include_descendants: bool = True,
    for_mutation: bool = False,
    ctx: context.CompilerContextLevel,
) -> pgast.RelRangeVar:
    """Return a Table corresponding to a given Link."""
    table_schema_name, table_name = common.get_pointer_backend_name(
        ptrref.id,
        ptrref.name.module,
        aspect=('table'
                if for_mutation or not include_descendants else 'inhview'),
        catenate=False,
    )

    if ptrref.name.module in {'cfg', 'sys'}:
        # Redirect all queries to schema tables to edgedbss
        table_schema_name = 'edgedbss'

    relation = pgast.Relation(schemaname=table_schema_name, name=table_name)

    # Pseudo pointers (tuple and type intersection) have no schema id.
    sobj_id = ptrref.id if isinstance(ptrref, irast.PointerRef) else None
    rvar = pgast.RelRangeVar(
        schema_object_id=sobj_id,
        relation=relation,
        include_inherited=include_descendants,
        alias=pgast.Alias(
            aliasname=ctx.env.aliases.get(ptrref.shortname.name)))

    return rvar
Esempio n. 2
0
def table_from_ptrref(ptrref: irast.PointerRef, *,
                      env: context.Environment) -> pgast.RangeVar:
    """Return a Table corresponding to a given Link."""
    table_schema_name, table_name = common.get_pointer_backend_name(
        ptrref.id, ptrref.module_id, catenate=False)

    if ptrref.shortname.module in {'schema', 'cfg', 'sys'}:
        # Redirect all queries to schema tables to edgedbss
        table_schema_name = 'edgedbss'

    relation = pgast.Relation(schemaname=table_schema_name, name=table_name)

    rvar = pgast.RangeVar(
        relation=relation,
        alias=pgast.Alias(aliasname=env.aliases.get(ptrref.shortname.name)))

    return rvar