get.porter.sh/porter@v1.3.0/pkg/storage/plugins/storage_protocol.go (about) 1 package plugins 2 3 import ( 4 "context" 5 6 "go.mongodb.org/mongo-driver/bson" 7 ) 8 9 // StorageProtocol is the interface that storage plugins must implement. 10 // This defines the protocol used to communicate with storage plugins. 11 type StorageProtocol interface { 12 // EnsureIndex makes sure that the specified index exists as specified. 13 // If it does exist with a different definition, the index is recreated. 14 EnsureIndex(ctx context.Context, opts EnsureIndexOptions) error 15 16 // Aggregate executes a pipeline and returns the results. 17 Aggregate(ctx context.Context, opts AggregateOptions) ([]bson.Raw, error) 18 19 // Count the number of results that match an optional query. 20 // When the query is omitted, the entire collection is counted. 21 Count(ctx context.Context, opts CountOptions) (int64, error) 22 23 // Find queries a collection, optionally projecting a subset of fields, and 24 // then returns the results as a list of bson documents. 25 Find(ctx context.Context, opts FindOptions) ([]bson.Raw, error) 26 27 // Insert a set of documents into a collection. 28 Insert(ctx context.Context, opts InsertOptions) error 29 30 // Patch applies a transformation to matching documents. 31 Patch(ctx context.Context, opts PatchOptions) error 32 33 // Remove matching documents from a collection. 34 Remove(ctx context.Context, opts RemoveOptions) error 35 36 // Update matching documents with the specified replacement document. 37 Update(ctx context.Context, opts UpdateOptions) error 38 } 39 40 // EnsureIndexOptions is the set of options available to the 41 // StorageProtocol.EnsureIndex operation. 42 type EnsureIndexOptions struct { 43 // Indices to create if not found. 44 Indices []Index 45 } 46 47 // Index on a collection. 48 type Index struct { 49 // Collection name to which the index applies. 50 Collection string 51 52 // Keys describes the fields and their sort order. 53 // Example: {"namespace": 1, "name": 1} 54 Keys bson.D 55 56 // Unique specifies if the index should enforce that the indexed fields for each document are unique. 57 Unique bool 58 } 59 60 // AggregateOptions is the set of options available to the 61 // StorageProtocol.Aggregate operation. 62 type AggregateOptions struct { 63 // Collection to query. 64 Collection string 65 66 // Pipeline document to aggregate, filter, and shape the results. 67 // See https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/ 68 Pipeline []bson.D 69 } 70 71 // CountOptions is the set of options available to the StorageProtocol.Count 72 // operation. 73 type CountOptions struct { 74 // Collection to query. 75 Collection string 76 77 // Query is a query filter document 78 // See https://docs.mongodb.com/manual/core/document/#std-label-document-query-filter 79 Filter bson.M 80 } 81 82 // FindOptions is the set of options available to the StorageProtocol.Find 83 // operation. 84 type FindOptions struct { 85 // Collection to query. 86 Collection string 87 88 // Sort is a list of field names by which the results should be sorted. 89 Sort bson.D 90 91 // Skip is the number of results to skip past and exclude from the results. 92 Skip int64 93 94 // Limit is the number of results to return. 95 Limit int64 96 97 // Select is a projection document 98 // See https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/ 99 Select bson.D 100 101 // Filter specifies how to filter the results. 102 // See https://docs.mongodb.com/manual/core/document/#std-label-document-query-filter 103 Filter bson.M 104 } 105 106 // InsertOptions is the set of options for the StorageProtocol.Insert operation. 107 type InsertOptions struct { 108 // Collection to query. 109 Collection string 110 111 // Documents is a set of documents to insert. 112 Documents []bson.M 113 } 114 115 // PatchOptions is the set of options for the StorageProtocol.Patch operation. 116 type PatchOptions struct { 117 // Collection to query. 118 Collection string 119 120 // Query is a query filter document 121 // See https://docs.mongodb.com/manual/core/document/#std-label-document-query-filter 122 QueryDocument bson.M 123 124 // Transformation is set of instructions to modify matching 125 // documents. 126 Transformation bson.D 127 } 128 129 // RemoveOptions is the set of options for the StorageProtocol.Remove operation. 130 type RemoveOptions struct { 131 // Collection to query. 132 Collection string 133 134 // Filter is a query filter document 135 // See https://docs.mongodb.com/manual/core/document/#std-label-document-query-filter 136 Filter bson.M 137 138 // All matching documents should be removed. Defaults to false, which only 139 // removes the first matching document. 140 All bool 141 } 142 143 // UpdateOptions is the set of options for the StorageProtocol.Update operation. 144 type UpdateOptions struct { 145 // Collection to query. 146 Collection string 147 148 // Filter is a query filter document 149 // See https://docs.mongodb.com/manual/core/document/#std-label-document-query-filter 150 Filter bson.M 151 152 // Upsert indicates that the document should be inserted if not found 153 Upsert bool 154 155 // Document is the replacement document. 156 Document bson.M 157 }