当前位置: 首页>>代码示例>>Golang>>正文


Golang pgx.Conn类代码示例

本文整理汇总了Golang中github.com/jackc/pgx.Conn的典型用法代码示例。如果您正苦于以下问题:Golang Conn类的具体用法?Golang Conn怎么用?Golang Conn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Conn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: insertRow

func insertRow(c *C, conn *pgx.Conn, n int) {
	_, err := conn.Exec("INSERT INTO test (id) VALUES ($1)", n)
	c.Assert(err, IsNil)
}
开发者ID:ably-forks,项目名称:flynn,代码行数:4,代码来源:postgres_test.go

示例2: mustPrepare

func mustPrepare(db *pgx.Conn, name, query string) *pgx.PreparedStatement {
	stmt, err := db.Prepare(name, query)
	if err != nil {
		log.Fatalf("Error when preparing statement %q: %s", query, err)
	}
	return stmt
}
开发者ID:tussion,项目名称:FrameworkBenchmarks,代码行数:7,代码来源:hello.go

示例3: ensureConnValid

// Do a simple query to ensure the connection is still usable
func ensureConnValid(t *testing.T, conn *pgx.Conn) {
	var sum, rowCount int32

	rows, err := conn.Query("select generate_series(1,$1)", 10)
	if err != nil {
		t.Fatalf("conn.Query failed: %v", err)
	}
	defer rows.Close()

	for rows.Next() {
		var n int32
		rows.Scan(&n)
		sum += n
		rowCount++
	}

	if rows.Err() != nil {
		t.Fatalf("conn.Query failed: %v", err)
	}

	if rowCount != 10 {
		t.Error("Select called onDataRow wrong number of times")
	}
	if sum != 55 {
		t.Error("Wrong values returned")
	}
}
开发者ID:segmentio,项目名称:pgx,代码行数:28,代码来源:helper_test.go

示例4: waitRow

func waitRow(c *C, conn *pgx.Conn, n int) {
	var res int64
	err := queryAttempts.Run(func() error {
		return conn.QueryRow("SELECT id FROM test WHERE id = $1", n).Scan(&res)
	})
	c.Assert(err, IsNil)
}
开发者ID:ably-forks,项目名称:flynn,代码行数:7,代码来源:postgres_test.go

示例5: execQuery64

func execQuery64(conn *pgx.Conn, stmt string, arguments ...interface{}) int64 {
	var err error
	var result int64
	err = conn.QueryRow(stmt, arguments...).Scan(&result)
	checkErr(err)
	return result
}
开发者ID:kelvich,项目名称:pg_tsdtm,代码行数:7,代码来源:perf.go

示例6: 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
}
开发者ID:segmentio,项目名称:pgx,代码行数:7,代码来源:helper_test.go

示例7: testJsonInt16ArrayFailureDueToOverflow

func testJsonInt16ArrayFailureDueToOverflow(t *testing.T, conn *pgx.Conn, typename string) {
	input := []int{1, 2, 234432}
	var output []int16
	err := conn.QueryRow("select $1::"+typename, input).Scan(&output)
	if err == nil || err.Error() != "can't scan into dest[0]: json: cannot unmarshal number 234432 into Go value of type int16" {
		t.Errorf("%s: Expected *json.UnmarkalTypeError, but got %v", typename, err)
	}
}
开发者ID:segmentio,项目名称:pgx,代码行数:8,代码来源:values_test.go

示例8: PrepareStatements

func PrepareStatements(conn *pgx.Conn) error {
	for name, sql := range preparedStatements {
		if _, err := conn.Prepare(name, sql); err != nil {
			return err
		}
	}
	return nil
}
开发者ID:maheshbale,项目名称:que-go,代码行数:8,代码来源:que.go

示例9: 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)
}
开发者ID:alternaDev,项目名称:georenting-server,代码行数:10,代码来源:models.go

示例10: mustPrepare

func mustPrepare(t testing.TB, conn *pgx.Conn, name, sql string) *pgx.PreparedStatement {
	ps, err := conn.Prepare(name, sql)
	if err != nil {
		t.Fatalf("Could not prepare %v: %v", name, err)
	}

	return ps
}
开发者ID:alaska,项目名称:pgx,代码行数:8,代码来源:helper_test.go

示例11: testJsonInt16ArrayFailureDueToOverflow

func testJsonInt16ArrayFailureDueToOverflow(t *testing.T, conn *pgx.Conn, typename string) {
	input := []int{1, 2, 234432}
	var output []int16
	err := conn.QueryRow("select $1::"+typename, input).Scan(&output)
	if _, ok := err.(*json.UnmarshalTypeError); !ok {
		t.Errorf("%s: Expected *json.UnmarkalTypeError, but got %v", typename, err)
	}
}
开发者ID:hellower,项目名称:pgx,代码行数:8,代码来源:values_test.go

示例12: 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
}
开发者ID:kelvich,项目名称:pg_tsdtm,代码行数:9,代码来源:perf.go

示例13: benchmarkSelectWithLog

func benchmarkSelectWithLog(b *testing.B, conn *pgx.Conn) {
	_, err := conn.Prepare("test", "select 1::int4, 'johnsmith', '[email protected]', 'John Smith', 'male', '1970-01-01'::date, '2015-01-01 00:00:00'::timestamptz")
	if err != nil {
		b.Fatal(err)
	}

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		var record struct {
			id            int32
			userName      string
			email         string
			name          string
			sex           string
			birthDate     time.Time
			lastLoginTime time.Time
		}

		err = conn.QueryRow("test").Scan(
			&record.id,
			&record.userName,
			&record.email,
			&record.name,
			&record.sex,
			&record.birthDate,
			&record.lastLoginTime,
		)
		if err != nil {
			b.Fatal(err)
		}

		// These checks both ensure that the correct data was returned
		// and provide a benchmark of accessing the returned values.
		if record.id != 1 {
			b.Fatalf("bad value for id: %v", record.id)
		}
		if record.userName != "johnsmith" {
			b.Fatalf("bad value for userName: %v", record.userName)
		}
		if record.email != "[email protected]" {
			b.Fatalf("bad value for email: %v", record.email)
		}
		if record.name != "John Smith" {
			b.Fatalf("bad value for name: %v", record.name)
		}
		if record.sex != "male" {
			b.Fatalf("bad value for sex: %v", record.sex)
		}
		if record.birthDate != time.Date(1970, 1, 1, 0, 0, 0, 0, time.Local) {
			b.Fatalf("bad value for birthDate: %v", record.birthDate)
		}
		if record.lastLoginTime != time.Date(2015, 1, 1, 0, 0, 0, 0, time.Local) {
			b.Fatalf("bad value for lastLoginTime: %v", record.lastLoginTime)
		}
	}
}
开发者ID:yunhor,项目名称:pgx,代码行数:56,代码来源:bench_test.go

示例14: testJsonStringArray

func testJsonStringArray(t *testing.T, conn *pgx.Conn, typename string) {
	input := []string{"foo", "bar", "baz"}
	var output []string
	err := conn.QueryRow("select $1::"+typename, input).Scan(&output)
	if err != nil {
		t.Errorf("%s: QueryRow Scan failed: %v", typename, err)
	}

	if !reflect.DeepEqual(input, output) {
		t.Errorf("%s: Did not transcode []string successfully: %v is not %v", typename, input, output)
	}
}
开发者ID:segmentio,项目名称:pgx,代码行数:12,代码来源:values_test.go

示例15: testJsonInt64Array

func testJsonInt64Array(t *testing.T, conn *pgx.Conn, typename string) {
	input := []int64{1, 2, 234432}
	var output []int64
	err := conn.QueryRow("select $1::"+typename, input).Scan(&output)
	if err != nil {
		t.Errorf("%s: QueryRow Scan failed: %v", typename, err)
	}

	if !reflect.DeepEqual(input, output) {
		t.Errorf("%s: Did not transcode []int64 successfully: %v is not %v", typename, input, output)
	}
}
开发者ID:segmentio,项目名称:pgx,代码行数:12,代码来源:values_test.go


注:本文中的github.com/jackc/pgx.Conn类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。