Example #1
0
func insert(tx *sqlx.Tx, sql string, v interface{}, id *string) error {
	rows, err := tx.NamedQuery(sql, v)
	if err != nil {
		return err
	}
	defer rows.Close()
	if rows.Next() {
		rows.Scan(id)
	} else {
		panic("expected id to be returned")
	}
	return nil
}
Example #2
0
func insert(tx *sqlx.Tx, sql string, v interface{}, returns ...interface{}) error {
	rows, err := tx.NamedQuery(sql, v)
	if err != nil {
		return err
	}
	defer rows.Close()
	if rows.Next() {
		for _, r := range returns {
			rows.Scan(r)
		}
	} else {
		panic("expected id to be returned")
	}
	return nil
}