Don Newton | 379ae25 | 2019-04-01 12:17:06 -0400 | [diff] [blame^] | 1 | // Copyright (C) MongoDB, Inc. 2017-present. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | // not use this file except in compliance with the License. You may obtain |
| 5 | // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | |
| 7 | package options |
| 8 | |
| 9 | // DeleteOptions represents all possible options to the deleteOne() and deleteMany() functions |
| 10 | type DeleteOptions struct { |
| 11 | Collation *Collation // Specifies a collation |
| 12 | } |
| 13 | |
| 14 | // Delete returns a pointer to a new DeleteOptions |
| 15 | func Delete() *DeleteOptions { |
| 16 | return &DeleteOptions{} |
| 17 | } |
| 18 | |
| 19 | // SetCollation specifies a collation |
| 20 | // Valid for servers >= 3.4. |
| 21 | func (do *DeleteOptions) SetCollation(c *Collation) *DeleteOptions { |
| 22 | do.Collation = c |
| 23 | return do |
| 24 | } |
| 25 | |
| 26 | // MergeDeleteOptions combines the argued DeleteOptions into a single DeleteOptions in a last-one-wins fashion |
| 27 | func MergeDeleteOptions(opts ...*DeleteOptions) *DeleteOptions { |
| 28 | dOpts := Delete() |
| 29 | for _, do := range opts { |
| 30 | if do == nil { |
| 31 | continue |
| 32 | } |
| 33 | if do.Collation != nil { |
| 34 | dOpts.Collation = do.Collation |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | return dOpts |
| 39 | } |