Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(select): support []Builder type in Where method #269

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ch3nnn
Copy link

@ch3nnn ch3nnn commented Jul 8, 2024

Extend the Where method in SelectStmt to accept a slice of Builder instances, allowing for multiple where conditions to be added conveniently in a single call.

Extend the Where method in SelectStmt to accept a slice of Builder
instances, allowing for multiple where conditions to be added
conveniently in a single call.
@ch3nnn
Copy link
Author

ch3nnn commented Jul 8, 2024

example:

func getWhere(req Request) (whereBuilder []dbr.Builder) {
	if req.ID > 0 {
		whereBuilder = append(whereBuilder, dbr.Eq("id", req.ID))
	}
	if req.Username != "" {
		whereBuilder = append(whereBuilder, dbr.Eq("username", req.Username))
	}

	return whereBuilder
}

func Example() {
	req := Request{ID: 1, Username: "xiaoming", Age: 18}
	Select("a", "b").From("table").Where(getWhere(req)).Load()
}

@ch3nnn
Copy link
Author

ch3nnn commented Jul 19, 2024

help to review it. thank!
@taylorchu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants