我正在尝试使用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 回答
- 0 关注
- 374 浏览
添加回答
举报
0/150
提交
取消