Support for composite types
Considering the following Prisma schema:
generator db {
provider = "go run github.com/steebchen/prisma-client-go"
}
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
avatar Avatar
}
type Avatar {
imageUrl String
}
Currently, the user model generated looks like this:
// InnerUser holds the actual data
type InnerUser struct {
ID string `json:"id"`
}
// RawUserModel is a struct for User when used in raw queries
type RawUserModel struct {
ID RawString `json:"id"`
}
// RelationsUser holds the relation data separately
type RelationsUser struct {
Avatar *AvatarModel `json:"avatar,omitempty"`
}
However this is not correct. Avatar should not be treated as a model. It is a composite type (a feature of Prisma for MongoDB).
[!NOTE] The code does not even work because
Avataris a type, not a model, so there is noAvatarModelgenerated.
- [x] I am open to work on this feature if you want
Yeah I started the feature here: https://github.com/steebchen/prisma-client-go/pull/1086 but haven't had the time to finish it as it needs some more work.
If you want to work on it I'd be happy to help and review, feel free to use the existing PR as a starting point if it helps.
I started to work on it based on your PR. The tests work now but I still need to work on Select and Where.
I open a new PR with my branch and you close your one?
Before I start working on Select and Where, here is my proposal:
| Typescript | Go equivalent | |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Are you ok with it?
Yes that looks great!