1 Star 0 Fork 18

llhhbc/openGauss-connector-go-pq

forked from openGauss/openGauss-connector-go-pq
暂停
 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
notice_example_test.go 708 Bytes
一键复制 编辑 原始数据 按行查看 历史
// +build go1.10
package pq_test
import (
"database/sql"
"fmt"
"log"
"gitee.com/opengauss/openGauss-connector-go-pq"
)
func ExampleConnectorWithNoticeHandler() {
name := ""
// Base connector to wrap
base, err := pq.NewConnector(name)
if err != nil {
log.Fatal(err)
}
// Wrap the connector to simply print out the message
connector := pq.ConnectorWithNoticeHandler(base, func(notice *pq.Error) {
fmt.Println("Notice sent: " + notice.Message)
})
db := sql.OpenDB(connector)
defer db.Close()
// Raise a notice
sql := "DO language plpgsql $$ BEGIN RAISE NOTICE 'test notice'; END $$"
if _, err := db.Exec(sql); err != nil {
log.Fatal(err)
}
// Output:
// Notice sent: test notice
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dreba/openGauss-connector-go-pq.git
git@gitee.com:dreba/openGauss-connector-go-pq.git
dreba
openGauss-connector-go-pq
openGauss-connector-go-pq
master

搜索帮助