olivierwilkinson / prisma-extension-soft-delete

Prisma extension for adding soft delete to Prisma models, even when using nested queries
Apache License 2.0
109 stars 16 forks source link

Query both non-deleted and deleted records #4

Closed thnam1410 closed 3 months ago

thnam1410 commented 1 year ago

Hi, first of all, thanks for your amazing library.

I'm facing problem with query table with non-deleted and deleted records.

I did try query like:

const where = {
    OR: [{ archivedAt: null }, { archivedAt: { not: null } }],
};

This is my table structure:

model Template {
    ...fields
    archivedAt DateTime?
}

I feel like this kind using "OR" is not convenient if we have more query conditions, do we have method or plan for a query that can include the deleted records? For example "TypeORM"

repository.withDelete().find()

Maybe the method for this library could be:

prisma.findManay({
    where: ...
    withDeleted: true
})
Hackder commented 12 months ago

Also, thank you for this library it is extremely helpful.

@thnam1410 You can achieve this behavior with the current state of this library. This is a valid workaround:

prisma.findMany({
    where: {
        archivedAt: {}
    }
});

I have tested this with nested relations, and findFirst calls and all of them work. But I am not sure how supported/stable this behavior is in Prisma. As of 5.6.0, this is a valid and working solution.

olivierwilkinson commented 11 months ago

Hi @thnam1410,

Thanks for raising this, I definitely do want to support querying both soft-deleted and non-deleted rows soon, I'll hopefully have time to get onto it over the Christmas period. It will likely have an API similar to your suggestion; I also want it to work in general (includes, selects, Typescript, etc).

@Hackder thank you for the workaround!

I'm really happy you are both finding the library helpful! Thank you for the kind words 🙏

AxelReid commented 6 months ago

How is it going on this?