sqlfixture.go
func (f *Fixture) Populate() {
	for _, t := range f.Tables {
		_, err := f.db.Exec(fmt.Sprintf("truncate %v", t.Name))
		if err != nil {
			panic(err)
		}
		for _, r := range t.Rows {
			q := "insert into %v (%v) values (?%v)"
			columns := ""
			values := make([]interface{}, len(r))
			i := 0
			for k, v := range r {
				columns += k + ","
				values[i] = v
				i++
			}
			columns = strings.Trim(columns, ",")
			q = fmt.Sprintf(q, t.Name, columns, strings.Repeat(",?", len(values)-1))

			_, err := f.db.Exec(q, values...)
			if err != nil {
				panic(err)
			}
		}
	}
}
func (f *Fixture) Populate() {
	for _, t := range f.Tables {
		_, err := f.db.Exec(fmt.Sprintf("truncate %v", t.Name))
		if err != nil {
			panic(err)
		}
		for _, r := range t.Rows {
			q := "insert into %v (%v) values (?%v)"
			columns := ""
			values := make([]interface{}, len(r))
			i := 0
			for k, v := range r {
				columns += k + ","
				values[i] = v
				i++
			}
			columns = strings.Trim(columns, ",")
			q = fmt.Sprintf(q, t.Name, columns, strings.Repeat(",?", len(values)-1))

			_, err := f.db.Exec(q, values...)
			if err != nil {
				panic(err)
			}
		}
	}
}
func ( f * Fixture ) Populate ( ) { for _ , t := range f . Tables { _ , err := f . db . Exec ( fmt . Sprintf ( " " , t . Name ) ) if err != nil { panic ( err ) } for _ , r := range t . Rows { q := " " columns := " " values := make ( [ ] interface { } , len ( r ) ) i := 0 for k , v := range r { columns += k + " " values [ i ] = v i ++ } columns = strings . Trim ( columns , " " ) q = fmt . Sprintf ( q , t . Name , columns , strings . Repeat ( " " , len ( values ) - 1 ) ) _ , err := f . db . Exec ( q , values ... ) if err != nil { panic ( err ) } } } }
// Populate the database tables within this fixture
// Warning: This will truncate any and all data for each table in the fixture
Populate the database tables within this fixture Warning : This will truncate any and all data for each table in the fixture