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

[Feature request] Separate delete field values and delete status #27

Open gylove1994 opened 2 months ago

gylove1994 commented 2 months ago

hi @olivierwilkinson,

While using this extension, I found a little strange place in createValue.

The createValue method must return a falsy value if the record is not deleted and a truthy value if it is deleted, which is limited the delete field value.

I have a project which is using a enum status "ENABLE" and "DISABLE" to determine the record is delete or not. So it cannot work well with the prisma-extension-soft-delete.

Thus I hope separate delete field values and delete status in config just like:

  createSoftDeleteExtension({
    models: {
      School: true,
    },
    defaultConfig: {
      field: 'status',
      createValue: (deleted: boolean) => (deleted ? Status.DISABLED : Status.ENABLED),
      //------------------v-----------------------------------------
      valueStatus: (value: Status) => value === Status.DISABLED,
      //------------------^-----------------------------------------
      allowToOneUpdates: true,
      allowCompoundUniqueIndexWhere: true
    }
  })