为了账号安全,请及时绑定邮箱和手机立即绑定

太多争论呼吁“github.com/jackc/pgx”。连接

太多争论呼吁“github.com/jackc/pgx”。连接

Go
HUWWW 2022-09-19 14:43:34
我正在尝试使用pgx打开与postgres数据库的连接,并且我收到以下错误:./dbservice.go:12:26: too many arguments in call to "github.com/jackc/pgx".Connect        have (context.Context, string)        want ("github.com/jackc/pgx".ConnConfig)./dbservice.go:13:18: too many arguments in call to conn.Close        have (context.Context)        want ()./dbservice.go:21:44: cannot use context.Background() (type context.Context) as type string in argument to conn.Query我不确定错误要求我在这里做什么。 当我从主文件调用它时可以工作,但在这里它不起作用。代码如下:pgx.Connectfunc initNodes(nodes *[]Node, searchNodes *[]SearchNode, storageNodes *[]StorageNode) error {    conn, err := pgx.Connect(context.Background(), DATABATE_URL)    defer conn.Close(context.Background())    if err != nil {        fmt.Printf("Connection failed: %v\n", err)        os.Exit(-1)    }...func main() {    a:= Arbiter{}    a.init()}有什么想法吗?
查看完整描述

1 回答

?
Smart猫小萌

TA贡献1911条经验 获得超7个赞

最有可能的是,您正在 导入 API,但 API 在您的“主文件”中。中的 Connect 函数接受要传递的两个参数。中的连接函数接受 代替 。v3pgxdbservice.gov4github.com/jackc/pgx/v4v3pkg.ConnConfig

因此,请检查 : 中的语句,如果您打算使用 API,请将其导入为 。importdbservice.gov4"github.com/jackc/pgx/v4"


查看完整回答
反对 回复 2022-09-19
  • 1 回答
  • 0 关注
  • 374 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号