Skip to content

Commit aa97c8b

Browse files
author
lifeng.lif
committed
feat: update default value
1 parent 647f145 commit aa97c8b

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

finder/finder.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,13 @@ func (f *Finder[T]) postActionHandler(ctx context.Context, globalOpContext *oper
127127
}
128128

129129
func (f *Finder[T]) FindOne(ctx context.Context, opts ...options.Lister[options.FindOneOptions]) (*T, error) {
130-
opts = append(opts, options.FindOne().SetSkip(f.skip).SetSort(f.sort))
130+
if f.sort != nil {
131+
opts = append(opts, options.FindOne().SetSort(f.sort))
132+
}
133+
if f.skip != 0 {
134+
opts = append(opts, options.FindOne().SetSkip(f.skip))
135+
}
136+
131137
t := new(T)
132138

133139
globalOpContext := operation.NewOpContext(f.collection, operation.WithDoc(t), operation.WithFilter(f.filter), operation.WithMongoOptions(opts), operation.WithModelHook(f.modelHook))
@@ -150,7 +156,15 @@ func (f *Finder[T]) FindOne(ctx context.Context, opts ...options.Lister[options.
150156
}
151157

152158
func (f *Finder[T]) Find(ctx context.Context, opts ...options.Lister[options.FindOptions]) ([]*T, error) {
153-
opts = append(opts, options.Find().SetSkip(f.skip).SetLimit(f.limit).SetSort(f.sort))
159+
if f.sort != nil {
160+
opts = append(opts, options.Find().SetSort(f.sort))
161+
}
162+
if f.skip != 0 {
163+
opts = append(opts, options.Find().SetSkip(f.skip))
164+
}
165+
if f.limit != 0 {
166+
opts = append(opts, options.Find().SetLimit(f.limit))
167+
}
154168

155169
t := make([]*T, 0)
156170

0 commit comments

Comments
 (0)