postgres.py 文件源码

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

项目:otree_virtual_machine_manager 作者: tobiasraabe 项目源码 文件源码
def delete_user(user_name: str):
        """Deletes a user's database, role and removes the entry from the user
        database. Returns the `http_port` variable to deny access to ports.

        Parameters
        ----------
        user_name : str
            Name of user account

        """

        with psycopg2.connect(**PSQL_CONN) as conn:
            conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
            cur = conn.cursor()
            cur.execute("""DELETE FROM {} WHERE user_name = '{}';"""
                        .format(PSQL_TABLE, user_name))
            cur.execute("""DROP DATABASE {};""".format(user_name))
            cur.execute("""DROP ROLE {};""".format(user_name))
        conn.close()

        click.secho('SUCCESS: User {} was removed from database.'
                    .format(user_name), fg='green')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号