Add support for custom-defined createValue function #16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposal:
We made changes so the condition in
createValue
property thatthe method must return a falsy value if the record is not deleted and vice versa
does not have to be forced. With the modification, we can definecreateValue
functions that have a custom value for whether the record is soft deleted or not. For example,new Date(0)
can be a value for a non-deleted record though it is truthy.Rationale:
We initially used
deletedAt: DateTime
as the field just like everyone else, with NULL representing a false value for being not deleted, and we were using Postgres as our underlying database. The problem arose with the following chain:deletedAt
as a UNIQUE CONSTRAINT, but in Postgres, NULL values are not considered distinct, which could bring many potential data integrity problems for us. More details in this post.0: number
to represent the value not being soft deleted. But the issue was BIGINT cannot be saved in JSON format.'0': string
as the default value for not being soft deleted, and stringfying the DateTime to represent a record has been soft deleted.Implementation:
We only changed a few lines in
lib/utils/resultFiltering.ts
so now the rows are filtered on an exact equality check with the value defined increateValue
function. SincedeletedAt
should really only contain two types of values -- one representing soft-deletedness, the other not being deleted, we believe an equality check is fine, as it is similar to what boolean is doing (one or the other). I also noted thatcreateValue(false)
was used extensively throughout the project so why discard checking equality with it during the filter stage?We are not sure if our change still serves the original purpose of what the package was doing, so please point out if we made a mistake in the fork.
Conclusion:
We really appreciate your work in opensourcing this soft-delete package, which Prisma doesn't support officially, and we believe you had your take and philosophy on designing the function to return only truthy/falsy values, as it's much simpler API defining what users can and should do. We propose this as an alternative to defining
createValue
in a truthy/falsy way, as defining in that way will still be supported under the current version.