如何使用 peewee db_url.connect() 生成与 RetryOperationalError 的连接?

How can I use peewee db_url.connect() to generate a connection with RetryOperationalError?

我默认使用带有 RetryOperationalError 的 PooledMySQLDatabase 生成数据库连接,如下所示:

from playhouse.shortcuts import RetryOperationalError
from playhouse.pool import PooledMySQLDatabase


class MySQLRetryDB(RetryOperationalError, PooledMySQLDatabase):
    pass


mysql_db = MySQLRetryDB('test_db')

现在我想使用 db_url.connect 生成这样的数据库连接:

from playhouse.db_url import connect
mysql_db = connect('mysql+pool://root:root@localhost:3306/test_db')

但是我找不到使用 RetryOperationalError 的方法,如何使用 connect() 生成与 RetryOperationalError 的连接?

我的解决方案是破解 db_url.schemes

class MySQLRetryDB(RetryOperationalError, PooledMySQLDatabase):
    pass


schemes['mysql+pool+retry'] = MySQLRetryDB


mysql_db = connect('mysql+pool+retry://root:root@localhost:3306/test_db')