|
| 1 | +// Copyright 2023 chenmingyong0423 |
| 2 | + |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | + |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package update |
| 16 | + |
| 17 | +import ( |
| 18 | + "github.com/chenmingyong0423/go-mongox/types" |
| 19 | + "go.mongodb.org/mongo-driver/bson" |
| 20 | +) |
| 21 | + |
| 22 | +func AddToSet(value any) bson.D { |
| 23 | + return bson.D{{Key: types.AddToSet, Value: value}} |
| 24 | +} |
| 25 | + |
| 26 | +func Pop(value any) bson.D { |
| 27 | + return bson.D{{Key: types.Pop, Value: value}} |
| 28 | +} |
| 29 | + |
| 30 | +func Pull(value any) bson.D { |
| 31 | + return bson.D{{Key: types.Pull, Value: value}} |
| 32 | +} |
| 33 | + |
| 34 | +func Push(value any) bson.D { |
| 35 | + return bson.D{{Key: types.Push, Value: value}} |
| 36 | +} |
| 37 | + |
| 38 | +func PullAll[T any](key string, values ...T) bson.D { |
| 39 | + return bson.D{{Key: types.PullAll, Value: bson.D{bson.E{Key: key, Value: values}}}} |
| 40 | +} |
| 41 | + |
| 42 | +func Each[T any](key string, values ...T) bson.D { |
| 43 | + return bson.D{{Key: key, Value: bson.D{{Key: types.Each, Value: values}}}} |
| 44 | +} |
| 45 | + |
| 46 | +func Position(key string, value any) bson.D { |
| 47 | + return bson.D{{Key: key, Value: bson.D{{Key: types.Position, Value: value}}}} |
| 48 | +} |
| 49 | + |
| 50 | +func Slice(key string, num int) bson.D { |
| 51 | + return bson.D{{Key: key, Value: bson.D{{Key: types.SliceForUpdate, Value: num}}}} |
| 52 | +} |
| 53 | + |
| 54 | +func Sort(key string, value any) bson.D { |
| 55 | + return bson.D{{Key: key, Value: bson.D{{Key: types.Sort, Value: value}}}} |
| 56 | +} |
| 57 | + |
| 58 | +func Set(value any) bson.D { |
| 59 | + return bson.D{{Key: types.Set, Value: value}} |
| 60 | +} |
| 61 | + |
| 62 | +func Unset(keys ...string) bson.D { |
| 63 | + value := bson.D{} |
| 64 | + for i := range keys { |
| 65 | + value = append(value, bson.E{Key: keys[i], Value: ""}) |
| 66 | + } |
| 67 | + return bson.D{{Key: types.Unset, Value: value}} |
| 68 | +} |
| 69 | + |
| 70 | +func SetOnInsert(value any) bson.D { |
| 71 | + return bson.D{{Key: types.SetOnInsert, Value: value}} |
| 72 | +} |
| 73 | + |
| 74 | +func CurrentDate(value any) bson.D { |
| 75 | + return bson.D{{Key: types.CurrentDate, Value: value}} |
| 76 | +} |
| 77 | + |
| 78 | +func Inc(value any) bson.D { |
| 79 | + return bson.D{{Key: types.Inc, Value: value}} |
| 80 | +} |
| 81 | + |
| 82 | +func Min(value any) bson.D { |
| 83 | + return bson.D{{Key: types.Min, Value: value}} |
| 84 | +} |
| 85 | + |
| 86 | +func Max(value any) bson.D { |
| 87 | + return bson.D{{Key: types.Max, Value: value}} |
| 88 | +} |
| 89 | + |
| 90 | +func Mul(value any) bson.D { |
| 91 | + return bson.D{{Key: types.Mul, Value: value}} |
| 92 | +} |
| 93 | + |
| 94 | +func Rename(value any) bson.D { |
| 95 | + return bson.D{{Key: types.Rename, Value: value}} |
| 96 | +} |
0 commit comments