Esempio n. 1
0
    def _get_pointer_column_target(self, schema, source, pointer_name, col):
        if col['column_type_schema'] == 'pg_catalog':
            col_type_schema = common.edgedb_module_name_to_schema_name('std')
            col_type = col['column_type']
        else:
            col_type_schema = col['column_type_schema']
            col_type = col['column_type']

        target = self.scalar_from_pg_type(col_type, col_type_schema, schema)
        return target, col['column_required']
Esempio n. 2
0
    async def read_modules(self, schema):
        schemas = await introspection.schemas.fetch(self.connection,
                                                    schema_pattern='edgedb_%')
        schemas = {
            s['name']
            for s in schemas if not s['name'].startswith('edgedb_aux_')
        }

        modules = await datasources.schema.modules.fetch(self.connection)
        modules = {
            common.edgedb_module_name_to_schema_name(m['name']): {
                'name': m['name'],
                'imports': m['imports']
            }
            for m in modules
        }

        recorded_schemas = set(modules.keys())

        # Sanity checks
        extra_schemas = schemas - recorded_schemas - {'edgedb', 'edgedbss'}
        missing_schemas = recorded_schemas - schemas

        if extra_schemas:
            msg = 'internal metadata incosistency'
            details = 'Extraneous data schemas exist: {}'.format(', '.join(
                '"%s"' % s for s in extra_schemas))
            raise s_err.SchemaError(msg, details=details)

        if missing_schemas:
            msg = 'internal metadata incosistency'
            details = 'Missing schemas for modules: {}'.format(', '.join(
                '{!r}'.format(s) for s in missing_schemas))
            raise s_err.SchemaError(msg, details=details)

        mods = []

        for module in modules.values():
            mod = s_mod.Module(name=module['name'])
            schema.add_module(mod)
            mods.append(mod)

        for mod in mods:
            for imp_name in mod.imports:
                if not schema.has_module(imp_name):
                    # Must be a foreign module, import it directly
                    try:
                        impmod = importlib.import_module(imp_name)
                    except ImportError:
                        # Module has moved, create a dummy
                        impmod = so.DummyModule(imp_name)

                    schema.add_module(impmod)
Esempio n. 3
0
def compile_FunctionCall(expr: irast.Base, *,
                         ctx: context.CompilerContextLevel) -> pgast.Base:
    funcobj = expr.func

    if funcobj.aggregate:
        raise RuntimeError(
            'aggregate functions are not supported in simple expressions')

    if funcobj.set_returning:
        raise RuntimeError(
            'set returning functions are not supported in simple expressions')

    args = [dispatch.compile(a, ctx=ctx) for a in expr.args]

    if funcobj.from_function:
        name = (funcobj.from_function, )
    else:
        name = (common.edgedb_module_name_to_schema_name(
            funcobj.shortname.module),
                common.edgedb_name_to_pg_name(funcobj.shortname.name))

    result = pgast.FuncCall(name=name, args=args)

    return result
Esempio n. 4
0
 def get_trigger_procname(self):
     schema = common.edgedb_module_name_to_schema_name(
         self.schema_constraint_name().module)
     proc_name = common.edgedb_name_to_pg_name(self.raw_constraint_name() +
                                               '_trigproc')
     return schema, proc_name