redis / redis-om-node

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

Idea: Save only properties defined in schema #221

Open MR4online opened 10 months ago

MR4online commented 10 months ago

hi, there!

Is it possible to save only the in the schema defined properties? Or to define properties, that will not be saved in redis?

Example:

Schema:

const test = new Schema("test", {
    uuid: {type: "string"}
});

and then I save data:

testRepository.save({ "uuid": 123, "user-language":"en" });

will result in having both properties (uuid and user-language) in the redis json object.

Currently it looks like i have to do this manually, but I like to keep the Data on the Object to use it later. so I would need to do something like:

const userLang = data["user-language"];
data["user-language"] = undefined;
data = testRepository.save({ "uuid": 123, "user-language":"en" });
data["user-language"] = userLang;

with multiple Properties or Objects as Properties, this is :-(

Idea:

const test = new Schema("test", {
    uuid: {type: "string"}
}, { saveSchemaOnly: true });

(which would be a simple solution to avoid saving unwanted data for unexperienced user as well) or

const test = new Schema("test", {
    uuid: {type: "string"},
    foo: {ignore: true}
});

Thanks.

Didas-git commented 10 months ago

This would be simple to implement actually, and its honestly the best way to go about it, saving things that arent defined on the schema usually isnt a great idea. However this was done because people have asked to be able to save anything even if not defined on the schema, i would also like to see an option for this like strict: true.

In short: +1 on this