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.02k stars 96 forks source link

Need a function `NotExists()` for columns not present in MongoDB #1275

Open merohitnishad opened 1 month ago

merohitnishad commented 1 month ago

I am using Prisma with MongoDB as the datasource and Go as the generator. Below is my setup:

datasource db {
    provider = "mongodb"
    url      = env("MONGO_URI")
}

generator db {
    provider = "go run github.com/steebchen/prisma-client-go"
}

model Company {
    id        String   @id @default(auto()) @map("_id") @db.ObjectId
    name      String
    address   String
    created_at DateTime @default(now())
    updated_at DateTime @updatedAt
    deleted_at DateTime?
}

Currently, the following query works only when the deleted_at column is present and is null in MongoDB:

var params []db.CustomerWhereParam
params = append(params, db.Customer.DeletedAt.IsNull())

However, I need support for a query where the deleted_at column does not exist in MongoDB, like this raw query:

{
  "deleted_at": { "$exists": false }
}

Proposed solution:

params = append(params, db.Customer.DeletedAt.NotExists())
steebchen commented 1 month ago

Yeah this is currently missing, I will look into this.

internal note: The field should be isset like in the JS client.