steebchen / prisma-client-go

Prisma Client Go is an auto-generated and fully type-safe database client
https://goprisma.org
Apache License 2.0
2.13k stars 95 forks source link

I new to goprisma and need some help with update #1395

Open manh7890 opened 3 days ago

manh7890 commented 3 days ago

Hi i have an issue with update here my model

model querylog {
  id                    String    @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
  table_names           String?
  start_timestamp       DateTime? @db.Timestamptz(6)
  query_duration        BigInt?
  status                String?
  total_matched_records BigInt?
  filter_conditions     String?
  description           String?
  query_creator_email   String
  created_date          DateTime? @default(now()) @db.Timestamptz(6)
  users                 users     @relation(fields: [query_creator_email], references: [email], onDelete: NoAction, onUpdate: NoAction, map: "fk_query_creator")
}

model task_manager_data {
  id                 String    @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
  status             String?
  log_message        String?
  type_of_task       String?
  task_creator_email String
  input              String?
  create_date        DateTime? @default(now()) @db.Timestamptz(6)
  users              users     @relation(fields: [task_creator_email], references: [email], onDelete: NoAction, onUpdate: NoAction, map: "fk_task_creator")
}

model users {
  id                String              @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
  email             String              @unique
  role              String?             @default("user") @db.VarChar(255)
  password_hash     String
  is_active         Boolean?            @default(true)

  querylog          querylog[]

  task_manager_data task_manager_data[]
}

i want to update email of user and all so update all the task_creator_email and query_creator_email to a new email to but i dont know where to start please help me if you know ho to do it thank

steebchen commented 3 days ago

You should try asking ChatGPT to help model your SQL schema and write it in Prisma schema. Maybe you want to remove the task_creator_email and instead use the user relation to the user to keep track of which user created a task_manager_data entry.

Then for actual Go code here is an example of updating records using fields or relations: https://goprisma.org/docs/walkthrough/update