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

Add default value to Schema

Open guyroyse opened this issue 2 years ago • 6 comments

It'd be nice to provide a default value to a Schema so that when an Entity is created, you don't have to set a field if you don't want to. Requested by @nraychaudhuri.

guyroyse avatar Apr 19 '22 16:04 guyroyse

Something like this?

class Album extends Entity { };

const schema = new Schema(Album)

schema.definition // { redis: { type: "string" } }

Didas-git avatar Apr 19 '22 17:04 Didas-git

Thinking this:

const schema = new Schema(Album, {
  artist: { type: 'string', default: 'Mushroomhead' },
  year: { type: 'number', default: 2020 }
}

guyroyse avatar Apr 19 '22 17:04 guyroyse

and

Thinking this:

const schema = new Schema(Album, {
  artist: { type: 'string', default: 'Mushroomhead' },
  year: { type: 'number', default: 2020 }
}

one more thing

how to add another schema in type array

{ "totalPlayer": 5, "players":[ { "key":"value" } ] }

hiteshpatelic avatar Apr 20 '22 11:04 hiteshpatelic

This has been asked for in several other issues and I am actively working on it.

guyroyse avatar Apr 20 '22 12:04 guyroyse

@guyroyse Any news?

eladcandroid avatar Jan 22 '23 12:01 eladcandroid

Code for nested objects in JSON is done and in a review process. Should be released next week when I get back from a conference.

guyroyse avatar Jan 23 '23 17:01 guyroyse