github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/vendor_skip/go.mongodb.org/mongo-driver/mongo/options/insertoptions.go (about)

     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  // InsertOneOptions represents options that can be used to configure an InsertOne operation.
    10  type InsertOneOptions struct {
    11  	// If true, writes executed as part of the operation will opt out of document-level validation on the server. This
    12  	// option is valid for MongoDB versions >= 3.2 and is ignored for previous server versions. The default value is
    13  	// false. See https://www.mongodb.com/docs/manual/core/schema-validation/ for more information about document
    14  	// validation.
    15  	BypassDocumentValidation *bool
    16  
    17  	// A string or document that will be included in server logs, profiling logs, and currentOp queries to help trace
    18  	// the operation.  The default value is nil, which means that no comment will be included in the logs.
    19  	Comment interface{}
    20  }
    21  
    22  // InsertOne creates a new InsertOneOptions instance.
    23  func InsertOne() *InsertOneOptions {
    24  	return &InsertOneOptions{}
    25  }
    26  
    27  // SetBypassDocumentValidation sets the value for the BypassDocumentValidation field.
    28  func (ioo *InsertOneOptions) SetBypassDocumentValidation(b bool) *InsertOneOptions {
    29  	ioo.BypassDocumentValidation = &b
    30  	return ioo
    31  }
    32  
    33  // SetComment sets the value for the Comment field.
    34  func (ioo *InsertOneOptions) SetComment(comment interface{}) *InsertOneOptions {
    35  	ioo.Comment = comment
    36  	return ioo
    37  }
    38  
    39  // MergeInsertOneOptions combines the given InsertOneOptions instances into a single InsertOneOptions in a last-one-wins
    40  // fashion.
    41  //
    42  // Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a
    43  // single options struct instead.
    44  func MergeInsertOneOptions(opts ...*InsertOneOptions) *InsertOneOptions {
    45  	ioOpts := InsertOne()
    46  	for _, ioo := range opts {
    47  		if ioo == nil {
    48  			continue
    49  		}
    50  		if ioo.BypassDocumentValidation != nil {
    51  			ioOpts.BypassDocumentValidation = ioo.BypassDocumentValidation
    52  		}
    53  		if ioo.Comment != nil {
    54  			ioOpts.Comment = ioo.Comment
    55  		}
    56  	}
    57  
    58  	return ioOpts
    59  }
    60  
    61  // InsertManyOptions represents options that can be used to configure an InsertMany operation.
    62  type InsertManyOptions struct {
    63  	// If true, writes executed as part of the operation will opt out of document-level validation on the server. This
    64  	// option is valid for MongoDB versions >= 3.2 and is ignored for previous server versions. The default value is
    65  	// false. See https://www.mongodb.com/docs/manual/core/schema-validation/ for more information about document
    66  	// validation.
    67  	BypassDocumentValidation *bool
    68  
    69  	// A string or document that will be included in server logs, profiling logs, and currentOp queries to help trace
    70  	// the operation.  The default value is nil, which means that no comment will be included in the logs.
    71  	Comment interface{}
    72  
    73  	// If true, no writes will be executed after one fails. The default value is true.
    74  	Ordered *bool
    75  }
    76  
    77  // InsertMany creates a new InsertManyOptions instance.
    78  func InsertMany() *InsertManyOptions {
    79  	return &InsertManyOptions{
    80  		Ordered: &DefaultOrdered,
    81  	}
    82  }
    83  
    84  // SetBypassDocumentValidation sets the value for the BypassDocumentValidation field.
    85  func (imo *InsertManyOptions) SetBypassDocumentValidation(b bool) *InsertManyOptions {
    86  	imo.BypassDocumentValidation = &b
    87  	return imo
    88  }
    89  
    90  // SetComment sets the value for the Comment field.
    91  func (imo *InsertManyOptions) SetComment(comment interface{}) *InsertManyOptions {
    92  	imo.Comment = comment
    93  	return imo
    94  }
    95  
    96  // SetOrdered sets the value for the Ordered field.
    97  func (imo *InsertManyOptions) SetOrdered(b bool) *InsertManyOptions {
    98  	imo.Ordered = &b
    99  	return imo
   100  }
   101  
   102  // MergeInsertManyOptions combines the given InsertManyOptions instances into a single InsertManyOptions in a last one
   103  // wins fashion.
   104  //
   105  // Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a
   106  // single options struct instead.
   107  func MergeInsertManyOptions(opts ...*InsertManyOptions) *InsertManyOptions {
   108  	imOpts := InsertMany()
   109  	for _, imo := range opts {
   110  		if imo == nil {
   111  			continue
   112  		}
   113  		if imo.BypassDocumentValidation != nil {
   114  			imOpts.BypassDocumentValidation = imo.BypassDocumentValidation
   115  		}
   116  		if imo.Comment != nil {
   117  			imOpts.Comment = imo.Comment
   118  		}
   119  		if imo.Ordered != nil {
   120  			imOpts.Ordered = imo.Ordered
   121  		}
   122  	}
   123  
   124  	return imOpts
   125  }