sequelize-typescript | typeorm | knex | bookshelf | objection
sequelize-typescript | typeorm
Basically i want to write raw sql and get a type safe object tree with relations eg. { a: { bs: [] } }
, but i understand this is not possible out of the box and i need mapping with some ORM. So i'm looking for these features
- mapping one-to-many to an object tree, eg: A one-to-many B => { a: { bs: [] } }
- all the orms get this
- knex: not by default, you have to use a very curious hack https://github.com/CoursePark/NestHydrationJS i still don't konw if it's brillant or bad, with this kind of libs an orm could be not neccessary at all.
- mapping with just classes and not schemas. This is because its so tedious to write the same attrs twice and i end up avoiding the mapping step.
- sequelize: classes and schema or just schema :/
- sequelize-typescript: this get the work done.
- typeorm: awesome! it have a repository pattern so i have a well separated code.
- bookshelf: not my style objection: not my style
- typescript support
- sequelize: yes, with both class and scheme definition :/ sequelize-typescript: this get the work done.
- typeorm: awesome! <3
- knex: yep, very nice
- bookshelf: ?
- objection: ?
- repository pattern is preferred
- sequelize: just support active record.
- sequelize-typescript: it enables this option but the class still extends of a superclass so your Person instances still have a lot of persistence attrs and methods.
- typeorm: yeah <3 awesome support both patterns and is well done, you can extends a super class to get active record or doesn't to get respository enabled with clean class code.
- flexible query-mapping system: I want to be able to add custom columns (eg. select sum(id) as count) without loosing the object tree, the result should be
{ a: { count: 4, bs: [] } }
- sequelize: the only one who get this done is sequelize (and obviously typescript-sequelize)
- typeorm: is great but if you want to add a custom column to the select you have to get the raw results loosing the object tree :/
- nice query system: the API have to be easy to guess, human readable, easy to learn
- sequelize: very nice, and very powerful (you can do very complex querys before fall into raw sql). It's not designed to think in sql.
- typeorm: very nice, an awesome querybuilder similar to knex, very intuitve if you think in sql.
- knex: very nice.
- mature query system: free of simplest bugs
- sequelize: it have been a lot of time in the market, well done, the result is what i expected.
- typeorm: it still have simple bugs like "the groupby issue" typeorm/typeorm#4814
- simple config
- sequelize-typescript: i had to make some hacks but it works. To have the models working in tests env i had to write
sequelize.models
first, so weird. - typeorm: yeah! <3 it works as the doc says, no pain.
- performance
- sequelize-typescript: i have used sequelize a year and yes, it generates weird queries but it doesn't seem to write wrong code, i didn't checked the excution plans because i never had a performance problem.
- typeorm: the generated queries are simpler as possible, it doesn't look bad, same as above i didn't checked the execution plan.
- support to the most rdbms as possible, I use to work with mssql and mysql, but i don't want to learn 3 libs
- sequelize: yep, so sequelize-typescript too
- typeorm: yep <3
- others doesn't
I voted for sequelize-typescript
because it have the highest scores in the important part mature and flexible querying system
, type safe
and easy and fast model definition (with @annotations)
.
I checked there is other very interesting options like photonjs, i will update this when i test it.
May be it's the time to give no-relational db's a chance
With libs like https://github.com/CoursePark/NestHydrationJS may be you don't need an ORM but it's still neccesary for
- refactor (if you used some leve of type safe)
- insert/update with all the attributes. In CRUDS we use to set all the attrs and it would be tedious if we have to set one by one.