redis-om-node icon indicating copy to clipboard operation
redis-om-node copied to clipboard

[Feature Request] Support reading objects when fields are missing in schema definition, but are present in Redis

Open marvinruder opened this issue 2 years ago • 1 comments

Suppose we have the following JSON object stored in Redis:

{
    essentialKey: "essentialValue",
    optionalKey: "optionalValue"
}

I now want to access this information using the following schema:

export const completeSchema = new Schema(MyEntity, {
  essentialKey: { type: "string" },
  optionalKey: { type: "string" },
});

This works fine.

However, in a different context I only want to access a part of the information stored in Redis:

export const essentialsOnlySchema = new Schema(MyEntity, {
  essentialKey: { type: "string" },
});

As of now, this does not work. Reading from a JSON object which contains keys that are not defined in our schema breaks at this line of code:

https://github.com/redis/redis-om-node/blob/bd6ab1ea52ae64f05649e418db94923f924cdfa5/lib/entity/entity.ts#L109

In our case this.entityFields[field] is undefined (since our entity does not contain a field called optionalKey), so fromRedisJson(…) does not exist.

Would it be possible to check for the existence of an entity field before invoking fromRedisJson(…) to allow using incomplete schema definitions?

marvinruder avatar Oct 09 '22 13:10 marvinruder

#135 same story

tnkarno avatar Oct 14 '22 19:10 tnkarno

+1 for that. Also, a bit of a beginner question on the same topic, what should we do if we want to change the schema by updating a field or removing it altogether? Doing any of these things causes the error mentioned by @marvinruder

gtupak avatar Nov 04 '22 14:11 gtupak

This will be coming with the 1.0 release.

guyroyse avatar Nov 04 '22 15:11 guyroyse

@guyroyse that's awesome, any estimated release date?

gtupak avatar Nov 05 '22 15:11 gtupak

I'm planning to release it at the end of the year. Which means it'll probably be January instead. ;)

guyroyse avatar Nov 15 '22 16:11 guyroyse

This was released with Redis OM 0.4.0 Beta. Install it with npm i redis-om@beta.

guyroyse avatar Mar 20 '23 18:03 guyroyse