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

Save JSON's array into JSON

Open pgamerx opened this issue 2 years ago • 3 comments

Hi there, I am not really experienced with redis or schemas and stuff and this is what I wanted to use:

Schema:

{
ID: string,
warns: [
{ reason: "Something", id: "1" },
{ reason: "something else", id: "2" }
]
}

How can I do this? I am really confused. Thanks!

pgamerx avatar Apr 24 '22 05:04 pgamerx

In the schema you would define the warns as an array (currently string[]) and on the interface (assuming you are using typescript) create a tuple.

interface YourInterface {
    ID: string;
    warns: [{ reason: string, id: string }];
}

Didas-git avatar Apr 25 '22 02:04 Didas-git

In the schema you would define the warns as an array (currently string[]) and on the interface (assuming you are using typescript) create a tuple.


interface YourInterface {

    ID: string;

    warns: [{ reason: string, id: string }];

}

Thanks, but does that mean I have to parse it as a JSON every time I want to get each and every warn? And also have to parse it as a string and push to the database?

pgamerx avatar Apr 25 '22 03:04 pgamerx

In the schema you would define the warns as an array (currently string[]) and on the interface (assuming you are using typescript) create a tuple.

interface YourInterface {

    ID: string;

    warns: [{ reason: string, id: string }];

}

Thanks, but does that mean I have to parse it as a JSON every time I want to get each and every warn? And also have to parse it as a string and push to the database?

In redis-om you should be able to just save the json, but if you have any issues regarding saving it directly as a json tell me because im actually not sure

Didas-git avatar Apr 25 '22 09:04 Didas-git

Redis OM only supports an array of strings right now and doesn't support nested object structures. The latter is being worked on.

guyroyse avatar Aug 29 '22 15:08 guyroyse