__init__.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:dustbunny 作者: Teamworksapp 项目源码 文件源码
def render_sql(db, q, inline=False):
    """
    Render the sql used by a query (only works for Postgres)

    :param q (query): an SQLAlchemy query object 
    :param inline (bool): inline parameters? 
    :return: str
    """
    compiled_statement = q.statement.compile(dialect=postgresql.dialect())
    pretty_statement = sql_format(str(compiled_statement), reindent=True)
    if inline:
        with db.session.connection().connection.connection.cursor() as cur:
            return cur.mogrify(pretty_statement, compiled_statement.params).decode('utf-8')
    else:
        return pretty_statement + ("\nparameters: {}".format(str(compiled_statement.params)) if compiled_statement.params else '')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号