PostgreSQL+;飞奔
我有以下代码:PostgreSQL+;飞奔,postgresql,dart,Postgresql,Dart,我有以下代码: void main() async { connection = PostgreSQLConnection('localhost', 5432, 'db', username: 'postgres', password: '12345'); await connection.open(); //... // some http handler that have next code inside: List<List<dynamic>
void main() async {
connection = PostgreSQLConnection('localhost', 5432, 'db', username: 'postgres', password: '12345');
await connection.open();
//...
// some http handler that have next code inside:
List<List<dynamic>> result = await connection.query(body['sql']).timeout(Duration(seconds: 90));
这很奇怪,因为在query
上我有超时90秒。所以它发生在连接上。但我只在main
中打开一次连接
有人能解释一下这是怎么发生的吗?如何修复它?PostgreSQLConnection有参数:timeoutInSeconds和queryTimeoutInSeconds,它们都默认为30。我建议您使用它们,而不是将来的超时。“而不是将来的超时”。您能解释更多细节吗?为什么我不应该在这里使用未来超时?Postgres驱动程序有内部超时(TimeOutingSeconds,QueryTimeOutingSeconds),它们的超时时间比您的要快,因为默认情况下它们是30秒,而您的是90秒。所以你需要增加这些。当你这样做的时候,就没有必要使用你未来的一个。但我需要哪一个超时?连接
和查询
超时之间有什么区别?当驱动程序打开到Postgres的连接时,会使用连接超时。执行查询时使用查询超时。从您的示例中,我假设您需要使用查询超时。
TimeoutException after 0:00:30.000000: Future not completed