def _run_codegen(qtree, *, pretty=True): codegen = pgcodegen.SQLSourceGenerator(pretty=pretty) try: codegen.visit(qtree) except pgcodegen.SQLSourceGeneratorError as e: # pragma: no cover ctx = pgcodegen.SQLSourceGeneratorContext(qtree, codegen.result) edgedb_error.add_context(e, ctx) raise except Exception as e: # pragma: no cover ctx = pgcodegen.SQLSourceGeneratorContext(qtree, codegen.result) err = pgcodegen.SQLSourceGeneratorError( 'error while generating SQL source') edgedb_error.add_context(err, ctx) raise err from e return codegen
def run_codegen( qtree: pgast.Base, *, pretty: bool = True, reordered: bool = False, ) -> str: codegen = pgcodegen.SQLSourceGenerator(pretty=pretty, reordered=reordered) try: codegen.visit(qtree) except pgcodegen.SQLSourceGeneratorError as e: # pragma: no cover ctx = pgcodegen.SQLSourceGeneratorContext(qtree, codegen.result) edgedb_error.add_context(e, ctx) raise except Exception as e: # pragma: no cover ctx = pgcodegen.SQLSourceGeneratorContext(qtree, codegen.result) err = pgcodegen.SQLSourceGeneratorError( 'error while generating SQL source') edgedb_error.add_context(err, ctx) raise err from e return ''.join(codegen.result)