prisma-client-go
prisma-client-go copied to clipboard
explain create one arguments
I have the following model:
model PonosJob {
id Bytes @id @db.Binary(26)
workerId Bytes? @db.Binary(26)
payload Json @db.Json
priority Int @default(0) @db.UnsignedTinyInt
retry Int @default(0) @db.UnsignedTinyInt
state PonosJobType @default(queued)
scheduledAt DateTime?
retryAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime? @updatedAt
deletedAt DateTime?
// relations
queue PonosJobQueue @relation(fields: [queueId], references: [id])
queueId Bytes @db.Binary(26)
PonosJobErrorMessage PonosJobErrorMessage[]
}
Trying to do an insert:
_, err := m.store.dbClient.PonosJob.CreateOne(
db.PonosJob.ID.Set([]byte(job.ID)),
db.PonosJob.QueueID.Set([]byte(job.QueueID)),
db.PonosJob.Payload.Set(job.Payload),
db.PonosJob.ScheduledAt.SetOptional(&job.ScheduledAt),
db.PonosJob.CreatedAt.Set(job.EnqueuedAt),
).Exec(m.store.ctx)
I'm getting
missing method queueFieldcompilerInvalidIfaceAssign
on all the fields.
Also when I run generate, I get:
go run github.com/prisma/prisma-client-go generate
../../../../pkg/mod/github.com/prisma/[email protected]/generator/types/types.go:6:2: missing go.sum entry for module providing package github.com/iancoleman/strcase (imported by github.com/prisma/prisma-client-go/generator/types); to add:
go get github.com/prisma/prisma-client-go/generator/[email protected]
../../../../pkg/mod/github.com/prisma/[email protected]/generator/types/types.go:7:2: missing go.sum entry for module providing package github.com/takuoki/gocase (imported by github.com/prisma/prisma-client-go/generator/types); to add:
go get github.com/prisma/prisma-client-go/generator/[email protected]
This is a new install and it's been difficult to get to this point. Thanks
Do you have more information about the error "missing method queueFieldcompilerInvalidIfaceAssign"? Where does it come from, when does it happen? Would be great to add as much info as possible.
The error you get before running generate for the first time is related to Go1.16 and tracked in #452.
Below are the following issues:
I am not understanding why I'm getting them as they are getting correct types. I have other tables, which have no problems at all and have the same fields in some cases.
db.PonosJob.QueueID:
cannot use db.PonosJob.QueueID.Set([]byte(job.QueueID)) (value of type db.ponosJobSetParam) as db.PonosJobWithPrismaPayloadSetParam value in argument to m.store.dbClient.PonosJob.CreateOne: missing method getQuerycompilerInvalidIfaceAssign
db.PonosJob.Payload:
cannot use db.PonosJob.Payload.Set(job.Payload) (value of type db.ponosJobWithPrismaPayloadSetParam) as db.PonosJobWithPrismaQueueSetParam value in argument to m.store.dbClient.PonosJob.CreateOne: missing method queueFieldcompilerInvalidIfaceAssign
db.PonosJob.ScheduledAt:
cannot use db.PonosJob.ScheduledAt.SetOptional(&job.ScheduledAt) (value of type db.ponosJobSetParam) as db.PonosJobWithPrismaPayloadSetParam value in argument to m.store.dbClient.PonosJob.CreateOne: missing method getQuerycompilerInvalidIfaceAssign
db.PonosJob.CreatedAt:
cannot use db.PonosJob.CreatedAt.Set(job.EnqueuedAt) (value of type db.ponosJobSetParam) as db.PonosJobWithPrismaQueueSetParam value in argument to m.store.dbClient.PonosJob.CreateOne: missing method getQuerycompilerInvalidIfaceAssign
That's super weird.. I tried to reproduce your schema and your query but it compiles for me. Is there any chance you can maybe send the full schema (if you don't want to share it publicly, you can also send it to [email protected])?
Thanks for sending the schema. It looks like the order doesn't match the expected one. If you check the arguments of CreateOne
, you can see that the expected order is id, payload, queue, scheduledAt, createdAt
. You can find this out by looking at the arguments of CreateOne.
I'm still not sure why you get this weird message, but when I
There is one bug currently which is that setting IDs directly (db.PonosJob.QueueID.Set) unfortunately doesn't work in CreateOne, but you can use the .Link
syntax instead:
_, err := client.PonosJob.CreateOne(
PonosJob.ID.Set([]byte(job.ID)),
PonosJob.Payload.Set(job.Payload),
PonosJob.Queue.Link(
PonosJobQueue.ID.Equals([]byte(job.QueueID)),
),
PonosJob.ScheduledAt.Set(time.Now()),
PonosJob.CreatedAt.Set(time.Now()),
).Exec(ctx)
I would have never guessed to look at CreateOne for the order. I would have taken it as the order of how the model is formed.
I know what to do for next time.
I'm not getting any more issues in the IDE. So thank you for your time.
I'm glad that it works now. The order should actually be the same as in the schema (id comes first, then payload, then at the bottom queue, and then the optional fields are listed).
@steebchen I run into this as well today having the same issue - I had looked at the quickstart briefly and run prisma-client-go but then took me a while to figure out. Perhaps worth stressing this in the docs further?