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

Generate models into separate `models` package

Open steebchen opened this issue 3 years ago • 1 comments

When querying for data, we already use the uppercase model name such as User for the query builder. This means we can't use the same name from the same package as a return type (e.g. of a FindOne call), which is why these types are currently suffixed with Model, such as UserModel. We could move those to a models package inside of whatever output folder is specified for the go client.

So, instead of:

func (x X) getUser() (prisma.UserModel, error) {
  return x.prisma.User.FindOne(
    db.User.ID.Equals("hi"),
  ).Exec(ctx)
}

the code could look like:

func (x X) getUser() (models.User, error) { // models: return type
  return x.prisma.User.FindOne(
    db.User.ID.Equals("hi"), // db: query builder etc.
  ).Exec(ctx)
}

steebchen avatar Sep 25 '20 09:09 steebchen

I like this. More concise api

tarrencev avatar Sep 25 '20 12:09 tarrencev