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

explain create one arguments

Open paulm17 opened this issue 3 years ago • 7 comments

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

paulm17 avatar May 18 '21 15:05 paulm17

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.

steebchen avatar May 18 '21 15:05 steebchen

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

paulm17 avatar May 18 '21 17:05 paulm17

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])?

steebchen avatar May 18 '21 17:05 steebchen

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)

steebchen avatar May 18 '21 19:05 steebchen

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.

paulm17 avatar May 18 '21 19:05 paulm17

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 avatar May 18 '21 19:05 steebchen

@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?

nettrino avatar Aug 30 '23 13:08 nettrino