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

[Advice] Chaining and Queries #88

Open
euca01 opened this issue Mar 30, 2020 · 0 comments
Open

[Advice] Chaining and Queries #88

euca01 opened this issue Mar 30, 2020 · 0 comments

Comments

@euca01
Copy link

euca01 commented Mar 30, 2020

Hi :),

I would like to chain a query though function. For example, i've :

err := db.Select("name").
	From("users").
	Where(dbx.HashExp{"UserId": 1}).
	One(&user)

And i would like to have something like that :

func ScopeByUserId( uID int ) {
    return Where(dbx.HashExp{"UserId": 1})
}

err := db.Select("name").
	From("users").
	ScopeByUserId( uID int ) .
	One(&user)

The idea is to be able to reuse the code. Is there a best pratice or advices for doing it ?

Thanks a lot for your help :)

@euca01 euca01 changed the title [Advise] Chaining and Queries [Advice] Chaining and Queries Mar 30, 2020
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

No branches or pull requests

1 participant