how can i exclude a field while finding model.
how can i do this? i can do this in javascript using select field. how can i do this in go client???
It's not possible yet in the Go client. Can you please describe why you want this feature? Is there a big field which you want to exclude for performance?
also see #346 for selecting fields
i dont want to user see hashedpassword
Good point! I'll put this into the 'soon' list, it would be indeed cool if specific fields could be ignored. However, note that specifically excluding fields might a bit dangerous as the default is returning all, so you might be better off to just selecting the fields you want. This is also not supported yet, but you can work around this by defining a new struct which just returns the fields you want:
user, err := db.User.FindUnique(...).Exec(ctx)
u := struct{
Name string `json:"string"`
}{
Name: user.Name,
}
// do something with u
return u
or
user, err := db.User.FindUnique(...).Exec(ctx)
newUser := db.UserModel{
ID: user.ID,
Name: user.Name,
}
return newUser
thank you for suggestion
Good point! I'll put this into the 'soon' list, it would be indeed cool if specific fields could be ignored. However, note that specifically excluding fields might a bit dangerous as the default is returning all, so you might be better off to just selecting the fields you want. This is also not supported yet, but you can work around this by defining a new struct which just returns the fields you want:
user, err := db.User.FindUnique(...).Exec(ctx) u := struct{ Name string `json:"string"` }{ Name: user.Name, } // do something with u return uor
user, err := db.User.FindUnique(...).Exec(ctx) newUser := db.UserModel{ ID: user.ID, Name: user.Name, } return newUser
This works but if i want to return a nested json with some fields that might be null in the database how should i approach that?
@Chalwe19 Can you please create a new discussion and elaborate on your problem? Thanks!
@steebchen any news on this feature? even with your suggestions, its a pain when you have to use FindMany as it adds a lot of unnecessary operations
@pikanezi
Not sure what you mean by "have to use FindMany". Using structs is indeed not ideal
I'm currently working on a few Go client things, feel free to sponsor me (or ask your employer) to potentially speed things up ;)
Regarding the implementation, it would most likely implementing select instead of implementing an exclude function (similar to what the JS client does).