Dynamically build queries, helper methods, some BREAKING CHANGES (see below)
🌟 **Help us spread the word about Prisma by starring the repo ☝️ or [tweeting](https://twitter.com/intent/tweet?text=Check%20out%20the%20latest%20Prisma%20Go%20Client%20release%20v0.3.1%20%F0%9F%9A%80%0D%0A%0D%0Ahttps://github.com/prisma/prisma-client-go/releases/tag/v0.4.0) about the release.**
Major changes
Dynamically build queries
Give your users more control over how they filter and order their data. Build up filters over time instead of all at once.
Here's an example of setting specific attributes dynamically:
go
func CreateUser(w http.ResponseWriter, r *http.Request) {
var params []db.UserSetParam
email := r.PostFormValue("email")
kind := r.PostFormValue("kind")
if kind == "customer" {
// Set the referrer for users of type customer only
params = append(params, db.User.Referer.Set(r.Header.Get("Referer"))
}
user, err := client.User.CreateOne(
db.User.Kind.Set(kind),
db.User.Email.Set(email),
params...,
).Exec(r.Context())
// ... Handle the response
}
Learn more in the [dynamic queries document](https://github.com/prisma/prisma-client-go/blob/master/docs/reference/16-dynamic-queries.md).
ExecInner helper method
Prisma uses a specific structure for its models. For some libraries, you might need a struct with pointer values instead of Prisma’s embedded structure.
For this case, you can use the .InnerX embedded structs to get the plain object. However, there was no method for results with slices before, so we introduced ExecInner:
go
users, err := client.User.FindMany().ExecInner(ctx)
doSomething(users)
Breaking changes
All methods returning structs now return a pointer to a struct
Methods in shape of (T, error) now return (*T, error):
go
user, err := client.User.FindMany().Exec(ctx)
// user was of type db.UserModel
// user is now of type *db.UserModel
log.Printf(“user: %+v”, *user)
Methods returning a primitive value such as count now returns struct
For more consistency, all methods which used to return a count-like value now return a pointer to a struct.
go
result, err := client.User.FindMany().Update(…).Exec(ctx)
// result was of type int before
// result is now a pointer to a struct
log.Printf(“user: %d”, result.Count)
This affects the following methods:
go
client.X.FindMany().Update().Exec(ctx)
client.X.FindMany().Delete().Exec(ctx)
client.ExecuteRaw(…).Exec(ctx)
Embedded model structs InternalX are renamed to InnerX
Internal might be misleading as it’s recommended to use the top-level return value wherever possible, but with some libraries you might need to use the embedded struct, so we renamed it to Inner to make it more clear what it does.
go
user, err := client.User.FindUnique()
// was called user.InternalUser before
// now is called user.InnerUser
doSomething(user.InnerUser)
Changes
* ci(test): remove verbose logs (375) steebchen
* fix(templates): rename internal->inner (376) steebchen
* feat(query): add ExecInner for find queries (373) steebchen
* fix(create): accept interface in CreateOne (378) steebchen
* fix(tests): throttle test setup schema generation (379) steebchen
* feat(client): export builder interfaces (380) steebchen
* feat(client): introduce result struct, use pointers (381) steebchen
* docs(reference): add dynamic queries docs (383) steebchen
* feat(prisma): upgrade to 2.16.0; adapt dmmf, publish & tests (384) steebchen
* ci(release-drafter): use minor version in template (385) steebchen
* fix(types): define count result in types (386) steebchen
* fix(types): rename count result to BatchResult (387) steebchen
* fix(raw): change int return value to BatchResult (388) steebchen
Contributors
steebchen
Interested in providing feedback for the Go client?
We would like to ask you a few questions and get your feedback about the Go client. We'll send merch along your away as a thank you.
If you're interested, email me at steebprisma.io or join our [public Slack](https://slack.prisma.io) and DM me.