redis / redis-om-node

Object mapping, and more, for Redis and Node.js. Written in TypeScript.
MIT License
1.18k stars 80 forks source link

overwrite schema setter #220

Open MR4online opened 1 year ago

MR4online commented 1 year ago

hi there,

I wonder if there is a way to overwrite the default setter of the schema (I thought I read something like this a while ago). So, when I have a schema like:

const AppModel = new Schema("app", {
    uuid: { type: "string" },
    name: { type: "string" }
});

I like to have some validation of the "name" in its setter. Lets say something like:

AppModel = {
   setName(value) {
      if (value.length >= 3)
         this.value = value.toLowerCase();
   }
}

I like having the db defition & input validation on one place.

kind regards!

Didas-git commented 1 year ago

I dont remember this being possible and the only way i see to do this right now would be using proxies on every created object which is really expensive.

However this is a rly great idea, to allow custom validators within the schema and i think its something that could get the enchancement tag