Beispiel #1
0
func TestQuery(t *testing.T) {
	var acct Accounting

	q := stquery.Statement(&acct, "select $fields from somewhere")
	if q != "select JobNumber, j_task_nunber, PETaskId, Name, CPU from somewhere" {
		t.Errorf("invalid query generated; got %q", q)
	}
	scan := newRowScanner(row)

	getter := stquery.NewGetter(&acct, scan)
	err := getter.Get()
	if err != nil {
		t.Fatal(err)
	}
	if !reflect.DeepEqual(acct, accountingValue) {
		t.Fatalf("got %+v", acct)
	}
}
Beispiel #2
0
func ExampleGetter(t *testing.T) {
	db := openDatabase()
	var row struct {
		Name string
		Age  int
	}
	rows, err := db.Query(stquery.Statement(&row, `SELECT $fields
		FROM sge_job
		WHERE j_job_number = $1 AND j_task_number = -1
		ORDER BY j_job_number DESC`))
	if err != nil {
		log.Fatal(err)
	}
	getter := stquery.NewGetter(&row, rows)
	for rows.Next() {
		if err := getter.Get(); err != nil {
			log.Fatal(err)
		}
	}
	fmt.Printf("got row %#v", row)
}