jawj / zapatos

Zero-abstraction Postgres for TypeScript: a non-ORM database library
https://jawj.github.io/zapatos/
Other
1.28k stars 46 forks source link

reflect-metadata #61

Open sfsr12 opened 3 years ago

sfsr12 commented 3 years ago

I have seen it mentioned - but is there any serious thought to implementing reflect-metadata and decorators?

The two use cases I would use them for are:

1.) Serialization/Deserialization of custom types. I know you can do this currently with types that can be converted - like JSON to an interface, etc - but with decorators you could add custom serialization/deserialization functions so that types could be used that need some sort of parsing. Example: int4range and stRange.js for ranges, numeric and decimal.js, etc - or just custom needs that go beyond just converting.

2.) Automatic support for casting in query. Right now you can wholesale change the default castArrayParamsToJson / castObjectParamsToJson - or specify cast using db.param(). This means when you don't hit the default - you can't just take a simple object - pass it in and have it work if that object contains a column that needs to be cast. You need to run it through db.param().

Are these things that you could see adding to this library or are they supported in a way I missed?

Would you accept a PR if I wanted to get something working related to this?

jawj commented 3 years ago

This is interesting. I haven't given it much thought until now.

I think it would probably add quite a lot of complexity, and so would need to add quite a lot of value in order to pay for itself.

I'm certainly willing to consider a PR — and to discuss any proofs of concept you come up with along the way.

sfsr12 commented 3 years ago

I will play with it over the next couple of weeks and see if there are simple places to add functionality and if they seem to add much value. I'll discuss with you before committing too much time to any one path. Is this where you prefer to discuss it or is there a discord/slack/etc?

jawj commented 3 years ago

Great, and no, this is the right place.

moltar commented 3 years ago

One of the main reasons I picked zapatos was because it was not using reflect and decorators. For that mess we already have TypeORM ;)