You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ElectroDB allows to remove optional properties with .remove(['property]) method. I would like to suggest to make it possible to use .set{ property: null }) to remove properties as well.
Use Case
I often find myself encapsulating entity updates in a single function that I can easily mock for unit tests, for example:
If I were to remove the discount field, currently, I would have to either create a second function which uses remove() or use conditionals to apply remove() if properties.discount === undefined:
// dedicated update function for removeconstupdateLocationRemoveDiscount=async(key,properties)=>{constresult=awaitStoreLocations.patch({ cityId, mallId, storeId, buildingId }).remove(["discount"]).where((attr,op)=>op.eq(attr.category,"food/coffee")).go();returnresult.data;}// apply remove conditionallyconstupdateLocation=async(key,properties)=>{letquery=StoreLocations.patch({ cityId, mallId, storeId, buildingId }).set({category: "food/meal"}).where((attr,op)=>op.eq(attr.category,"food/coffee"));if('discount'inproperties&&properties.discount===undefined)query=query.remove(["discount"])constresult=awaitquery.go();returnresult.data;}
In the second case I have to be careful to distinguish between properties.discount is undefined because it is not available on properties or because it was set to undefined explicitly. Allowing for null values on set() would solve this nicely I think.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
ElectroDB allows to remove optional properties with
.remove(['property])
method. I would like to suggest to make it possible to use.set{ property: null })
to remove properties as well.Use Case
I often find myself encapsulating entity updates in a single function that I can easily mock for unit tests, for example:
If I were to remove the
discount
field, currently, I would have to either create a second function which usesremove()
or use conditionals to applyremove()
ifproperties.discount === undefined
:In the second case I have to be careful to distinguish between
properties.discount
isundefined
because it is not available onproperties
or because it was set toundefined
explicitly. Allowing fornull
values onset()
would solve this nicely I think.Beta Was this translation helpful? Give feedback.
All reactions