diff --git a/option.go b/option.go index 6866395..a8fe2a6 100644 --- a/option.go +++ b/option.go @@ -7,7 +7,9 @@ // Date : 2022-05-15 11:43 package database -import "git.zhangdeman.cn/zhangdeman/op_type" +import ( + "git.zhangdeman.cn/zhangdeman/op_type" +) // SetOption 设置选项 // @@ -63,7 +65,7 @@ func WithTable(tableName string) SetOption { // Author : go_developer@163.com<白茶清欢> // // Date : 12:17 2022/5/15 -func WithWhere(where map[string]interface{}) SetOption { +func WithWhere[T op_type.BaseType](where map[string]T) SetOption { return func(o *Option) { if nil == o.Where { o.Where = make(map[string]interface{}) @@ -91,8 +93,14 @@ func WithLimit[T op_type.Int](limit T, offset T) SetOption { // Author : go_developer@163.com<白茶清欢> // // Date : 12:23 2022/5/15 -func WithIn(field string, value interface{}) SetOption { +func WithIn[T op_type.Array](field string, value T) SetOption { return func(o *Option) { + if nil == value { + return + } + if len(value) == 0 { + return + } if nil == o.In { o.In = make(map[string]interface{}) } @@ -105,12 +113,18 @@ func WithIn(field string, value interface{}) SetOption { // Author : go_developer@163.com<白茶清欢> // // Date : 12:24 2022/5/15 -func WithBatchIn(batchIn map[string]interface{}) SetOption { +func WithBatchIn[T op_type.Array](batchIn map[string]T) SetOption { return func(o *Option) { if nil == o.In { o.In = make(map[string]interface{}) } for field, value := range batchIn { + if nil == value { + continue + } + if len(value) == 0 { + continue + } o.In[field] = value } } @@ -121,11 +135,14 @@ func WithBatchIn(batchIn map[string]interface{}) SetOption { // Author : go_developer@163.com<白茶清欢> // // Date : 16:18 2022/5/15 -func WithNotIn(field string, value interface{}) SetOption { +func WithNotIn[T op_type.Array](field string, value T) SetOption { return func(o *Option) { if nil == o.NotIn { o.NotIn = make(map[string]interface{}) } + if value == nil || len(value) == 0 { + return + } o.NotIn[field] = value } } @@ -135,12 +152,15 @@ func WithNotIn(field string, value interface{}) SetOption { // Author : go_developer@163.com<白茶清欢> // // Date : 16:23 2022/5/15 -func WithBatchNotIn(data map[string]interface{}) SetOption { +func WithBatchNotIn[T op_type.Array](data map[string]T) SetOption { return func(o *Option) { if nil == o.NotIn { o.NotIn = make(map[string]interface{}) } for field, value := range data { + if value == nil || len(value) == 0 { + continue + } o.NotIn[field] = value } } @@ -216,6 +236,9 @@ func WithLike(field string, value string) SetOption { if nil == o.Like { o.Like = make(map[string]string) } + if len(value) == 0 { + return + } o.Like[field] = value } } @@ -231,6 +254,9 @@ func WithBatchLike(data map[string]string) SetOption { o.Like = make(map[string]string) } for field, value := range data { + if len(value) == 0 { + continue + } o.Like[field] = value } } @@ -246,6 +272,9 @@ func WithNotLike(field string, value string) SetOption { if nil == o.NotLike { o.NotLike = make(map[string]string) } + if len(value) == 0 { + return + } o.NotLike[field] = value } } @@ -261,6 +290,9 @@ func WithBatchNotLike(data map[string]string) SetOption { o.NotLike = make(map[string]string) } for field, value := range data { + if len(value) == 0 { + continue + } o.NotLike[field] = value } } @@ -271,7 +303,7 @@ func WithBatchNotLike(data map[string]string) SetOption { // Author : go_developer@163.com<白茶清欢> // // Date : 17:31 2022/5/15 -func WithNotEqual(field string, value interface{}) SetOption { +func WithNotEqual[T op_type.BaseType](field string, value T) SetOption { return func(o *Option) { if nil == o.NotEqual { o.NotEqual = make(map[string]interface{}) @@ -285,7 +317,7 @@ func WithNotEqual(field string, value interface{}) SetOption { // Author : go_developer@163.com<白茶清欢> // // Date : 17:33 2022/5/15 -func WithBatchNotEqual(data map[string]interface{}) SetOption { +func WithBatchNotEqual[T op_type.BaseType](data map[string]T) SetOption { return func(o *Option) { if nil == o.NotEqual { o.NotEqual = make(map[string]interface{})