mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-05-11 20:49:47 +08:00
- 引入 third_party/highgo-pq 作为 HighGo 专用驱动实现 - 调整驱动注册与连接入口,避免覆盖 postgres 驱动 - 保持 PG 数据源行为不变并补充接入文档
35 lines
698 B
Go
35 lines
698 B
Go
//go:build go1.10
|
|
// +build go1.10
|
|
|
|
package pq_test
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
"log"
|
|
|
|
"github.com/lib/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
|
|
}
|