Replies: 2 comments
-
A syntax idea for the extension API, inspired by the JS client. extended := client.Prisma.Extend( // <- golang generics, yay! :D
db.OnAll(func(model Model, operation Operation, query Query, args Args) Result {
log.Printf("on all: model: %s, operation: %s, args: %+v", model, operation, Args)
switch model {
case UserModelName:
log.Printf("is user!")
}
// TODO: how would you modify the query? 🤔
return query()
}),
// is this too generic?
db.On([]Operation{extension.FindUnique}, []Model{UserModelName}, func(model Model, operation Operation, query Query, args Args) Result {
return query()
}),
// alternatively or additionally, all operation and model combinations with fully type-safe args
db.OnUserFindFirst(func (args UserArgs, query UserFindFirstQuery) UserFindFirstResult {
if args.Password != nil {
log.Printf("user changed their password!")
}
return query()
})
) |
Beta Was this translation helpful? Give feedback.
0 replies
-
I'm playing around here regarding syntax, this is highly experimental and not functional: prisma-client-go/test/features/extension/default_test.go Lines 22 to 124 in 2ddbf5e |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Discussion for client extensions in the Go client.
This is useful to add hooks for queries and features such as RLS.
Some general notes:
Beta Was this translation helpful? Give feedback.
All reactions