Skip to content
Discussion options

You must be logged in to vote

First, I really like that you're using query mods beyond just what is generated by default.
The power of mods are that you can create your own to do whatever you want.

In your example, you're pretty close. The thing is... the mod doesn't HAVE TO do anything. Try this:

func OptionalWhere[V any](
	where func(val V) mods.Where[*dialect.SelectQuery],
	value *V,
) bob.Mod[*dialect.SelectQuery] {
	if value != nil {
		return where(*value)
	}

	return bob.ModFunc[*dialect.SelectQuery](func(*dialect.SelectQuery) {})
}

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@absolutejam
Comment options

@absolutejam
Comment options

@stephenafamo
Comment options

Answer selected by stephenafamo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants