當前位置: 首頁>>代碼示例>>Golang>>正文


Golang pgx.Conn類代碼示例

本文整理匯總了Golang中github.com/flynn/flynn/Godeps/_workspace/src/github.com/jackc/pgx.Conn的典型用法代碼示例。如果您正苦於以下問題:Golang Conn類的具體用法?Golang Conn怎麽用?Golang Conn使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Conn類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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: ", 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: ", err)
	}

	if rowCount != 10 {
		t.Error("Select called onDataRow wrong number of times")
	}
	if sum != 55 {
		t.Error("Wrong values returned")
	}
}
開發者ID:devick,項目名稱:flynn,代碼行數:28,代碼來源:helper_test.go

示例2: 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:eldarion-gondor,項目名稱:cli,代碼行數:7,代碼來源:postgres_test.go

示例3: 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:devick,項目名稱:flynn,代碼行數:7,代碼來源:helper_test.go

示例4: 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:justintung,項目名稱:flynn,代碼行數:8,代碼來源:values_test.go

示例5: 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:justintung,項目名稱:flynn,代碼行數:8,代碼來源:que.go

示例6: unlistenAndRelease

func unlistenAndRelease(pool *pgx.ConnPool, conn *pgx.Conn, channel string) {
	_, err := conn.Exec(fmt.Sprintf(sqlUnlisten, channel))
	if err != nil {
		conn.Close()
		return
	}
	pool.Release(conn)
}
開發者ID:josephwinston,項目名稱:flynn,代碼行數:8,代碼來源:data_store.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.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:devick,項目名稱:flynn,代碼行數:8,代碼來源:values_test.go

示例8: 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:josephwinston,項目名稱:flynn,代碼行數:8,代碼來源:helper_test.go

示例9: 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:devick,項目名稱:flynn,代碼行數:56,代碼來源:bench_test.go

示例10: 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:devick,項目名稱:flynn,代碼行數:12,代碼來源:values_test.go

示例11: 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:devick,項目名稱:flynn,代碼行數:12,代碼來源:values_test.go

示例12: waitReadWrite

func waitReadWrite(c *C, conn *pgx.Conn) {
	var readOnly string
	err := queryAttempts.Run(func() error {
		if err := conn.QueryRow("SHOW default_transaction_read_only").Scan(&readOnly); err != nil {
			return err
		}
		if readOnly == "off" {
			return nil
		}
		return fmt.Errorf("transaction readonly is %q", readOnly)
	})
	c.Assert(err, IsNil)
}
開發者ID:eldarion-gondor,項目名稱:cli,代碼行數:13,代碼來源:postgres_test.go

示例13: testJsonSingleLevelStringMap

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

	if !reflect.DeepEqual(input, output) {
		t.Errorf("%s: Did not transcode map[string]string successfully: %v is not %v", typename, input, output)
		return
	}
}
開發者ID:devick,項目名稱:flynn,代碼行數:14,代碼來源:values_test.go

示例14: waitRecovered

func waitRecovered(c *C, conn *pgx.Conn) {
	var recovery bool
	err := queryAttempts.Run(func() error {
		err := conn.QueryRow("SELECT pg_is_in_recovery()").Scan(&recovery)
		if err != nil {
			return err
		}
		if recovery {
			return fmt.Errorf("in recovery")
		}
		return nil
	})
	c.Assert(err, IsNil)
}
開發者ID:eldarion-gondor,項目名稱:cli,代碼行數:14,代碼來源:postgres_test.go

示例15: testJsonNestedMap

func testJsonNestedMap(t *testing.T, conn *pgx.Conn, typename string) {
	input := map[string]interface{}{
		"name":      "Uncanny",
		"stats":     map[string]interface{}{"hp": float64(107), "maxhp": float64(150)},
		"inventory": []interface{}{"phone", "key"},
	}
	var output map[string]interface{}
	err := conn.QueryRow("select $1::"+typename, input).Scan(&output)
	if err != nil {
		t.Errorf("%s: QueryRow Scan failed: %v", typename, err)
		return
	}

	if !reflect.DeepEqual(input, output) {
		t.Errorf("%s: Did not transcode map[string]interface{} successfully: %v is not %v", typename, input, output)
		return
	}
}
開發者ID:devick,項目名稱:flynn,代碼行數:18,代碼來源:values_test.go


注:本文中的github.com/flynn/flynn/Godeps/_workspace/src/github.com/jackc/pgx.Conn類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。