func (db Database) Exec(ctx context.Context, queries ...Query) error {
	ctx, cancelFunc := context.WithTimeout(ctx, db.QueryPeriod)
	defer cancelFunc()
	tx, err := db.DB.BeginTx(ctx, nil)
	if err != nil {
		return fmt.Errorf("beginning transaction: %w", err)
	}
	for i, q := range queries {
		result, err := tx.ExecContext(ctx, q.Cmd(), q.Args()...)
		if f, ok := q.(ExecFunction); err == nil && ok {
			var n int64
			n, err = result.RowsAffected()
			if err == nil && n != 1 {
				err = fmt.Errorf("wanted to update 1 row, but updated %d when calling %s", n, f.name)
			}
		}
		if err != nil {
			err = fmt.Errorf("executing query %v: %w", i, err)
			err2 := tx.Rollback()
			if err2 != nil {
				return fmt.Errorf("rolling back transaction due to %v: %w", err, err2)
			}
			return err
		}
	}
	if err := tx.Commit(); err != nil {
		return fmt.Errorf("committing transaction: %w", err)
	}
	return nil
}
// Exec evaluates multiple queries in a transaction, ensuring each execSQLFunction one only updates one row.
Exec evaluates multiple queries in a transaction, ensuring each execSQLFunction one only updates one row.
// Exec evaluates multiple queries in a transaction ensuring each execSQLFunction one only updates one row .
func (db Database) Exec(ctx context.Context, queries ...Query) error {
	ctx, cancelFunc := context.WithTimeout(ctx, db.QueryPeriod)
	defer cancelFunc()
	tx, err := db.DB.BeginTx(ctx, nil)
	if err != nil {
		return fmt.Errorf("beginning transaction: %w", err)
	}
	for i, q := range queries {
		result, err := tx.ExecContext(ctx, q.Cmd(), q.Args()...)
		if f, ok := q.(ExecFunction); err == nil && ok {
			var n int64
			n, err = result.RowsAffected()
			if err == nil && n != 1 {
				err = fmt.Errorf("wanted to update 1 row, but updated %d when calling %s", n, f.name)
			}
		}
		if err != nil {
			err = fmt.Errorf("executing query %v: %w", i, err)
			err2 := tx.Rollback()
			if err2 != nil {
				return fmt.Errorf("rolling back transaction due to %v: %w", err, err2)
			}
			return err
		}
	}
	if err := tx.Commit(); err != nil {
		return fmt.Errorf("committing transaction: %w", err)
	}
	return nil
}
func ( db Database ) Exec ( ctx context . Context , queries ... Query ) error { ctx , cancelFunc := context . WithTimeout ( ctx , db . QueryPeriod ) defer cancelFunc ( ) tx , err := db . DB . BeginTx ( ctx , nil ) if err != nil { return fmt . Errorf ( " " , err ) } for i , q := range queries { result , err := tx . ExecContext ( ctx , q . Cmd ( ) , q . Args ( ) ... ) if f , ok := q . ( ExecFunction ) ; err == nil && ok { var n int64 n , err = result . RowsAffected ( ) if err == nil && n != 1 { err = fmt . Errorf ( " " , n , f . name ) } } if err != nil { err = fmt . Errorf ( " " , i , err ) err2 := tx . Rollback ( ) if err2 != nil { return fmt . Errorf ( " " , err , err2 ) } return err } } if err := tx . Commit ( ) ; err != nil { return fmt . Errorf ( " " , err ) } return nil }
Exec evaluates multiple queries in a transaction, ensuring each execSQLFunction one only updates one row.
Exec evaluates multiple queries in a transaction ensuring each execSQLFunction one only updates one row .