github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/vendor_skip/go.mongodb.org/mongo-driver/mongo/options/dboptions.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 import ( 10 "go.mongodb.org/mongo-driver/bson/bsoncodec" 11 "go.mongodb.org/mongo-driver/mongo/readconcern" 12 "go.mongodb.org/mongo-driver/mongo/readpref" 13 "go.mongodb.org/mongo-driver/mongo/writeconcern" 14 ) 15 16 // DatabaseOptions represents options that can be used to configure a Database. 17 type DatabaseOptions struct { 18 // ReadConcern is the read concern to use for operations executed on the Database. The default value is nil, which means that 19 // the read concern of the Client used to configure the Database will be used. 20 ReadConcern *readconcern.ReadConcern 21 22 // WriteConcern is the write concern to use for operations executed on the Database. The default value is nil, which means that the 23 // write concern of the Client used to configure the Database will be used. 24 WriteConcern *writeconcern.WriteConcern 25 26 // ReadPreference is the read preference to use for operations executed on the Database. The default value is nil, which means that 27 // the read preference of the Client used to configure the Database will be used. 28 ReadPreference *readpref.ReadPref 29 30 // BSONOptions configures optional BSON marshaling and unmarshaling 31 // behavior. 32 BSONOptions *BSONOptions 33 34 // Registry is the BSON registry to marshal and unmarshal documents for operations executed on the Database. The default value 35 // is nil, which means that the registry of the Client used to configure the Database will be used. 36 Registry *bsoncodec.Registry 37 } 38 39 // Database creates a new DatabaseOptions instance. 40 func Database() *DatabaseOptions { 41 return &DatabaseOptions{} 42 } 43 44 // SetReadConcern sets the value for the ReadConcern field. 45 func (d *DatabaseOptions) SetReadConcern(rc *readconcern.ReadConcern) *DatabaseOptions { 46 d.ReadConcern = rc 47 return d 48 } 49 50 // SetWriteConcern sets the value for the WriteConcern field. 51 func (d *DatabaseOptions) SetWriteConcern(wc *writeconcern.WriteConcern) *DatabaseOptions { 52 d.WriteConcern = wc 53 return d 54 } 55 56 // SetReadPreference sets the value for the ReadPreference field. 57 func (d *DatabaseOptions) SetReadPreference(rp *readpref.ReadPref) *DatabaseOptions { 58 d.ReadPreference = rp 59 return d 60 } 61 62 // SetBSONOptions configures optional BSON marshaling and unmarshaling behavior. 63 func (d *DatabaseOptions) SetBSONOptions(opts *BSONOptions) *DatabaseOptions { 64 d.BSONOptions = opts 65 return d 66 } 67 68 // SetRegistry sets the value for the Registry field. 69 func (d *DatabaseOptions) SetRegistry(r *bsoncodec.Registry) *DatabaseOptions { 70 d.Registry = r 71 return d 72 } 73 74 // MergeDatabaseOptions combines the given DatabaseOptions instances into a single DatabaseOptions in a last-one-wins 75 // fashion. 76 // 77 // Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a 78 // single options struct instead. 79 func MergeDatabaseOptions(opts ...*DatabaseOptions) *DatabaseOptions { 80 d := Database() 81 82 for _, opt := range opts { 83 if opt == nil { 84 continue 85 } 86 if opt.ReadConcern != nil { 87 d.ReadConcern = opt.ReadConcern 88 } 89 if opt.WriteConcern != nil { 90 d.WriteConcern = opt.WriteConcern 91 } 92 if opt.ReadPreference != nil { 93 d.ReadPreference = opt.ReadPreference 94 } 95 if opt.Registry != nil { 96 d.Registry = opt.Registry 97 } 98 } 99 100 return d 101 }