Exemple #1
0
func BenchmarkFormatQueryWithStructMethods(b *testing.B) {
	rec := &Record{
		Num1: 1,
		Num2: 2,
		Num3: 3,
		Str1: randSeq(100),
		Str2: randSeq(200),
		Str3: randSeq(300),
	}
	for i := 0; i < b.N; i++ {
		_, err := pg.FormatQuery(`
			SELECT ?GetNum1, ?GetNum2, ?GetNum3, ?GetStr1, ?GetStr2, ?GetStr3
			WHERE 1=1 AND 2=2
		`, rec)
		if err != nil {
			b.Fatal(err)
		}
	}
}
Exemple #2
0
func BenchmarkFormatQueryWithArgs(b *testing.B) {
	rec := &Record{
		Num1: 1,
		Num2: 2,
		Num3: 3,
		Str1: randSeq(100),
		Str2: randSeq(200),
		Str3: randSeq(300),
	}
	for i := 0; i < b.N; i++ {
		_, err := pg.FormatQuery(`
			SELECT ?, ?, ?, ?, ?, ?
			WHERE 1=1 AND 2=2
		`, rec.Num1, rec.Num2, rec.Num3, rec.Str1, rec.Str2, rec.Str3)
		if err != nil {
			b.Fatal(err)
		}
	}
}
Exemple #3
0
func BenchmarkFormatQueryWithoutArgs(b *testing.B) {
	rec := &Record{
		Num1: 1,
		Num2: 2,
		Num3: 3,
		Str1: randSeq(100),
		Str2: randSeq(200),
		Str3: randSeq(300),
	}
	q := fmt.Sprintf(`
		SELECT %d, %d, %d, '%s', '%s', '%s'
		WHERE 1=1 AND 2=2
	`, rec.Num1, rec.Num2, rec.Num3, rec.Str1, rec.Str2, rec.Str3)
	for i := 0; i < b.N; i++ {
		_, err := pg.FormatQuery(q)
		if err != nil {
			b.Fatal(err)
		}
	}
}
Exemple #4
0
func ExampleInts_in() {
	ids := pg.Ints{1, 2, 3}
	q, err := pg.FormatQuery(`SELECT * FROM table WHERE id IN (?)`, ids)
	fmt.Println(q, err)
	// Output: SELECT * FROM table WHERE id IN (1,2,3) <nil>
}