本文整理汇总了Golang中github.com/jackc/pgx.Conn.Exec方法的典型用法代码示例。如果您正苦于以下问题:Golang Conn.Exec方法的具体用法?Golang Conn.Exec怎么用?Golang Conn.Exec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jackc/pgx.Conn
的用法示例。
在下文中一共展示了Conn.Exec方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: mustExec
func mustExec(t testing.TB, conn *pgx.Conn, sql string, arguments ...interface{}) (commandTag pgx.CommandTag) {
var err error
if commandTag, err = conn.Exec(sql, arguments...); err != nil {
t.Fatalf("Exec unexpectedly failed with %v: %v", sql, err)
}
return
}
示例2: prepQue
// prepQue ensures that the que table exists and que's prepared statements are
// run. It is meant to be used in a pgx.ConnPool's AfterConnect hook.
func prepQue(conn *pgx.Conn) error {
_, err := conn.Exec(queTableSQL)
if err != nil {
return err
}
return que.PrepareStatements(conn)
}
示例3: execUpdate
func execUpdate(conn *pgx.Conn, stmt string, arguments ...interface{}) bool {
var err error
// fmt.Println(stmt)
_, err = conn.Exec(stmt, arguments...)
//if err != nil {
// fmt.Println(err)
//}
return err == nil
}
示例4: TestPoolReleaseDiscardsDeadConnections
func TestPoolReleaseDiscardsDeadConnections(t *testing.T) {
t.Parallel()
// Run timing sensitive test many times
for i := 0; i < 50; i++ {
func() {
maxConnections := 3
pool := createConnPool(t, maxConnections)
defer pool.Close()
var c1, c2 *pgx.Conn
var err error
var stat pgx.ConnPoolStat
if c1, err = pool.Acquire(); err != nil {
t.Fatalf("Unexpected error acquiring connection: %v", err)
}
defer func() {
if c1 != nil {
pool.Release(c1)
}
}()
if c2, err = pool.Acquire(); err != nil {
t.Fatalf("Unexpected error acquiring connection: %v", err)
}
defer func() {
if c2 != nil {
pool.Release(c2)
}
}()
if _, err = c2.Exec("select pg_terminate_backend($1)", c1.Pid); err != nil {
t.Fatalf("Unable to kill backend PostgreSQL process: %v", err)
}
// do something with the connection so it knows it's dead
rows, _ := c1.Query("select 1")
rows.Close()
if rows.Err() == nil {
t.Fatal("Expected error but none occurred")
}
if c1.IsAlive() {
t.Fatal("Expected connection to be dead but it wasn't")
}
stat = pool.Stat()
if stat.CurrentConnections != 2 {
t.Fatalf("Unexpected CurrentConnections: %v", stat.CurrentConnections)
}
if stat.AvailableConnections != 0 {
t.Fatalf("Unexpected AvailableConnections: %v", stat.CurrentConnections)
}
pool.Release(c1)
c1 = nil // so it doesn't get released again by the defer
stat = pool.Stat()
if stat.CurrentConnections != 1 {
t.Fatalf("Unexpected CurrentConnections: %v", stat.CurrentConnections)
}
if stat.AvailableConnections != 0 {
t.Fatalf("Unexpected AvailableConnections: %v", stat.CurrentConnections)
}
}()
}
}
示例5: exec
func exec(conn *pgx.Conn, stmt string, arguments ...interface{}) {
var err error
// fmt.Println(stmt)
_, err = conn.Exec(stmt, arguments...)
checkErr(err)
}
示例6: insertRow
func insertRow(c *C, conn *pgx.Conn, n int) {
_, err := conn.Exec("INSERT INTO test (id) VALUES ($1)", n)
c.Assert(err, IsNil)
}
示例7: createTable
func createTable(c *C, conn *pgx.Conn) {
_, err := conn.Exec("CREATE TABLE test (id bigint PRIMARY KEY)")
c.Assert(err, IsNil)
insertRow(c, conn, 1)
}