redis-om-node
redis-om-node copied to clipboard
Use reflection to do object mapping for a more declarative API.
Currently using the schema in ts looks like this. This feels like 2x the code necessary since you are declaring the schema twice. With reflection the API would be more declarative and make this code much smaller and easier to understand.
Without reflection:
interface Album {
artist: string;
title: string;
year: number;
genres: string[];
outOfPublication: boolean;
}
class Album extends Entity {}
let schema = new Schema(Album, {
artist: { type: 'string' },
title: { type: 'string' },
year: { type: 'number' },
genres: { type: 'array' },
outOfPublication: { type: 'boolean' }
})
With reflection:
@Entity()
class Album {
@Property()
artist: string;
@Property()
title: string;
@Property()
year: string;
@Property()
genres: string[];
@Property()
outOfPublication: boolean;
}
let schema = new Schema(Album);
This is just an example but demonstrates how declarative and powerful reflection can make this api.
You're right and this bugged me too. I thought about it for a good long while and chose not to use decorators because a) they are still an experimental feature and b) the experience from a JavaScript developer's point of view was not nearly as tidy. Settled on the lowest common denominator.
I understand your reasoning however there are a couple of thing I want to add to the table.
a) Thinking about decorators as an experimental feature should not dismay you from using them. Plenty of production ready frameworks use decorators successfully such as Angular and Nestjs.
b) Furthermore only because you support decorators does not mean that you only support a declarative decorator API. It is possible to support both. What i mean is, this current api should be ablo co-exist with a declarative decoration API without any breaking changes. Which in turn should not make js developers frown away from using it :)
I agree with point B. I suspect point A will be resolved by the time I get to adding this feature. ;) I'll add it to the backlog.
Hello I am max-abclabs but on my private github account.
I could look into this when I have some time over and submit a PR if you don't mind?
This issue is obviated but Redis OM 0.4 which eliminates the Entity class. Closing.
This issue is obviated but Redis OM 0.4 which eliminates the Entity class. Closing.
Can you elaborate? I'm currently looking for a way to use decorators to declare my entities using this library, is this supported now 2 years later?