|
|
@@ -40,16 +40,22 @@ type Simple[LI any, RI any] struct {
|
|
|
// 查询右实体关联使用的请求参数,注意是Query类型
|
|
|
RightQueryQueryParams request.Query
|
|
|
|
|
|
+ // 查询左实体带右实体信息使用的请求参数,注意是Query类型
|
|
|
+ LeftQueryWithRightQueryParams request.Query
|
|
|
+
|
|
|
+ // 查询右实体带左实体信息使用的请求参数,注意是Query类型
|
|
|
+ RightQueryWithLeftQueryParams request.Query
|
|
|
+
|
|
|
// 可选配置项,通过WithXXX配置
|
|
|
- options *Options[LI, RI]
|
|
|
+ options *Options
|
|
|
}
|
|
|
|
|
|
func (simple *Simple[LI, RI]) bind(binder *binding.Binder) {
|
|
|
//options := simple.options
|
|
|
}
|
|
|
|
|
|
-func BindSimple[LI any, RI any](binder *binding.Binder, simple *Simple[LI, RI], opts ...Option[LI, RI]) {
|
|
|
- options := new(Options[LI, RI])
|
|
|
+func BindSimple[LI any, RI any](binder *binding.Binder, simple *Simple[LI, RI], opts ...Option) {
|
|
|
+ options := new(Options)
|
|
|
|
|
|
for _, opt := range opts {
|
|
|
opt(options)
|
|
|
@@ -60,9 +66,9 @@ func BindSimple[LI any, RI any](binder *binding.Binder, simple *Simple[LI, RI],
|
|
|
simple.bind(binder)
|
|
|
}
|
|
|
|
|
|
-type Option[LI any, RI any] func(options *Options[LI, RI])
|
|
|
+type Option func(options *Options)
|
|
|
|
|
|
-type Options[LI any, RI any] struct {
|
|
|
+type Options struct {
|
|
|
// 左实体中指向右实体的字段
|
|
|
leftRelationField string
|
|
|
|
|
|
@@ -92,64 +98,82 @@ type Options[LI any, RI any] struct {
|
|
|
|
|
|
// 关闭右侧查询
|
|
|
disableRightQuery bool
|
|
|
+
|
|
|
+ // 关闭左实体带右实体信息查询
|
|
|
+ disableLeftWithRightQuery bool
|
|
|
+
|
|
|
+ // 关闭右实体带左实体信息查询
|
|
|
+ disableRightWithLeftQuery bool
|
|
|
}
|
|
|
|
|
|
-func WithLeftRelationField[LI any, RI any](leftRelationField string) Option[LI, RI] {
|
|
|
- return func(options *Options[LI, RI]) {
|
|
|
+func WithLeftRelationField(leftRelationField string) Option {
|
|
|
+ return func(options *Options) {
|
|
|
options.leftRelationField = leftRelationField
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithRightRelationField[LI any, RI any](rightRelationField string) Option[LI, RI] {
|
|
|
- return func(options *Options[LI, RI]) {
|
|
|
+func WithRightRelationField(rightRelationField string) Option {
|
|
|
+ return func(options *Options) {
|
|
|
options.rightRelationField = rightRelationField
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithLeftRelationColumn[LI any, RI any](leftRelationColumn string) Option[LI, RI] {
|
|
|
- return func(options *Options[LI, RI]) {
|
|
|
+func WithLeftRelationColumn(leftRelationColumn string) Option {
|
|
|
+ return func(options *Options) {
|
|
|
options.leftRelationColumn = leftRelationColumn
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithRightRelationColumn[LI any, RI any](rightRelationColumn string) Option[LI, RI] {
|
|
|
- return func(options *Options[LI, RI]) {
|
|
|
+func WithRightRelationColumn(rightRelationColumn string) Option {
|
|
|
+ return func(options *Options) {
|
|
|
options.rightRelationColumn = rightRelationColumn
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithDisableLeft[LI any, RI any]() Option[LI, RI] {
|
|
|
- return func(options *Options[LI, RI]) {
|
|
|
+func WithDisableLeft() Option {
|
|
|
+ return func(options *Options) {
|
|
|
options.disableLeft = true
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithDisableRight[LI any, RI any]() Option[LI, RI] {
|
|
|
- return func(options *Options[LI, RI]) {
|
|
|
+func WithDisableRight() Option {
|
|
|
+ return func(options *Options) {
|
|
|
options.disableRight = true
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithDisableLeftUpdate[LI any, RI any]() Option[LI, RI] {
|
|
|
- return func(options *Options[LI, RI]) {
|
|
|
+func WithDisableLeftUpdate() Option {
|
|
|
+ return func(options *Options) {
|
|
|
options.disableLeftUpdate = true
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithDisableLeftQuery[LI any, RI any]() Option[LI, RI] {
|
|
|
- return func(options *Options[LI, RI]) {
|
|
|
+func WithDisableLeftQuery[LI any, RI any]() Option {
|
|
|
+ return func(options *Options) {
|
|
|
options.disableLeftQuery = true
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithDisableRightUpdate[LI any, RI any]() Option[LI, RI] {
|
|
|
- return func(options *Options[LI, RI]) {
|
|
|
+func WithDisableRightUpdate() Option {
|
|
|
+ return func(options *Options) {
|
|
|
options.disableRightUpdate = true
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithDisableRightQuery[LI any, RI any]() Option[LI, RI] {
|
|
|
- return func(options *Options[LI, RI]) {
|
|
|
+func WithDisableRightQuery[LI any, RI any]() Option {
|
|
|
+ return func(options *Options) {
|
|
|
options.disableRightQuery = true
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func WithDisableLeftWithRightQuery[LI any, RI any]() Option {
|
|
|
+ return func(options *Options) {
|
|
|
+ options.disableLeftWithRightQuery = true
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func WithDisableRightWithLeftQuery() Option {
|
|
|
+ return func(options *Options) {
|
|
|
+ options.disableRightWithLeftQuery = true
|
|
|
+ }
|
|
|
+}
|