如何在 Go 中不使用“database/sql”包运行 PostgreSql 查询?

问题描述 投票:0回答:1

我想运行像 libpq-fe 这样的 sql 查询。我已阅读https://go.dev/src/database/sql/doc.txt,但我不明白驱动程序接口有什么好处。

样品:

    connStr := "dbname=postgres replication=database"
    pqConn, err := pq.ConnectDB(connStr)

    pqResult, err := pq.Exec("IDENTIFY_SYSTEM")
    fields, err := pqResult.Fields()
    tuples, err := pgResult.Tuples()

    err := pqConn.SendQuery("BASE_BACKUP")
    pqResult, err := pgConn.GetResult()

是否有一个包可以运行这样的 PostgreSql 查询?

postgresql go oop
1个回答
0
投票

是的,有很多 postgreSQL 驱动程序包,其中一个例子是

https://github.com/jackc/pgx https://github.com/lib/pq

© www.soinside.com 2019 - 2024. All rights reserved.