douling8772 2018-11-06 21:22
浏览 48
已采纳

使用带有Go上下文作为参数的SQL函数是否是一种好习惯?

I have RESTFUL web service in Golang and I'm using it's SQL driver for database. my question is should I use SQL functions with context as parameter or without it? For instance, there are both QueryContext and Query methods.

Actually I do know what is the context in Go, I just don't know why I should send it to the database methods.

  • 写回答

1条回答 默认 最新

  • dongzhong1929 2018-11-06 21:40
    关注

    Context aware methods allow for cancellable query execution.

    The way the cancellation is handled is driver specific, but even if the driver is not directly supports taking the context any query that was started with a context should be closed when the context is closed.

    This should help with potential connection leaks and query specific timeouts.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办