在不生成新连接的情况下更新 torndb 连接时区
update torndb connection timezone without spawning a new connection
假设您在 API 上使用 torndb
打开了一个新的数据库连接
db_conn = torndb.Connection(ip,
database,
user=user,
password=password,
time_zone="UTC",
charset="utf8")
在代码中初始声明后,是否可以将连接时区编辑为其他时区,或者是否需要使用更新后的时区生成新连接。
我尝试使用 db_conn.time_zone
访问 torndb.Connection 对象,但我 运行 进入 AttributeError: 'Connection' object has no attribute 'time_zone'
.
您不能直接更改连接对象 afaik 的时区。但是,您可以做的是 运行 查询,每当您需要更改时区(例如 SET time_zone = "foo/bar";
并执行它时,只要连接会话存在,您就可以通过这种方式动态更改时区。
假设您在 API 上使用 torndb
打开了一个新的数据库连接db_conn = torndb.Connection(ip,
database,
user=user,
password=password,
time_zone="UTC",
charset="utf8")
在代码中初始声明后,是否可以将连接时区编辑为其他时区,或者是否需要使用更新后的时区生成新连接。
我尝试使用 db_conn.time_zone
访问 torndb.Connection 对象,但我 运行 进入 AttributeError: 'Connection' object has no attribute 'time_zone'
.
您不能直接更改连接对象 afaik 的时区。但是,您可以做的是 运行 查询,每当您需要更改时区(例如 SET time_zone = "foo/bar";
并执行它时,只要连接会话存在,您就可以通过这种方式动态更改时区。