Skip to content

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