prisma-client-go icon indicating copy to clipboard operation
prisma-client-go copied to clipboard

Stripped json

Open fragdance1 opened this issue 2 years ago • 2 comments

When working on Select statement I noticed that the returned json contains a lot of empty fields. Perhaps not a problem, but I like my json neat and tidy.

For instance, when using Select I get this:

bild

i.e. overview, still etc are null, empty strings etc.

I've created an ExecJson-function (to be used instead of Exec) that returns the following json

bild

The one downside is that since we retrieve the data as json we can't do any manipulation (unless, of course, we unmarshal it, but that negates the whole thing), but if we just want to retrieve slim data this might be an idea?

fragdance1 avatar Jul 04 '22 18:07 fragdance1

Can you elaborate what you are using this function for? Like why do you want to get raw json data instead of a type like User?

Also, can you elaborate what the exact signature of ExecJson would be?

steebchen avatar Jul 05 '22 16:07 steebchen

I'm coming from a frontend perspective where I want to download as little data as possible. Ffor instance, in my pet project that I'm porting from express/nodejs I've got 900+ movies with videofiles, cast, crew, genres and details. Things can quickly add up.

The signature I'm using is: ExecJson(ctx context.Context) (j []byte, err error)

So I use it like: movies,err := db.Movie.... Select([]string{"title,"id"] ExecJson(context.Background())

w.Write(movies)

fragdance1 avatar Jul 05 '22 17:07 fragdance1

This is now available in the main branch, you can try it out by running go get github.com/prisma/prisma-client-go@main. It's not yet released, but I'll cut a new one soon!

steebchen avatar Jan 29 '23 13:01 steebchen