Fetching data from sqlboiler in golang

708 Views Asked by At

I am using sqlboiler and golang

using this code I fetch all details from the database.

userDemo, erro := dbmodels.UserDemographics().All(ctx, m.db)

UserDemographic table contain 2 columns, userId and count

how can I fetch the data the userId=1 from userDemo. (we can pass userId=1 in function All, that is not I want)

after fetching the data from db(here eg userDemo), how can I get each row of data diffeneltly

1

There are 1 best solutions below

0
On

The requirement here is for a search. There are two places this can be achieved, either you try to query specific userid or with all results in hand, you can try to run it through a searching algorithm. Given that you are using go, there is no idiomatic way to achieve this in a one-liner.

The best possible way is to write a for loop for userDemo. If you want, there is a library called funk which can help you with this search.