Answer the question
In order to leave comments, you need to log in
ORM in nodeJS, how should it work?
Why do I need an ORM? - to simplify the process of saving / retrieving objects in the database. I googled a lot, looked at examples of different libraries, highlighted mainly Sequelize and Bookshelf. In general, they seemed to me to be some kind of query constructors, it doesn’t seem at all that any of them is designed to simplify my life and significantly reduce the SQL code in scripts, but just the opposite, in addition to SQL, I need to study the api of these libs.
For example, it’s easier for me to write SQL by hand than to write such a miracle:
users.findOne({
order: [
['username', 'DESC'],
sequelize.fn('max', sequelize.col('age')),
[sequelize.fn('max', sequelize.col('age')), 'DESC'],
[sequelize.fn('otherfunction', sequelize.col('col1'), 12, 'lalala'), 'DESC'],
[User, 'name', 'DESC'],
[{model: User, as: 'Friend'}, 'name', 'DESC'],
[User, Company, 'name', 'DESC'],
]
order: 'convert(user_name using gbk)'
order: 'username DESC'
order: sequelize.literal('convert(user_name using gbk)')
})
Answer the question
In order to leave comments, you need to log in
It's not clear what you want to get. But you can look at typeorm . This is the only orm in node.js that implements the data mapper pattern, all others implement the active record pattern. But the sampling conditions still have to be written.
Google metaprogramming and dynamic code generation and interpretation. Python, for example, has an exec() function that takes a string containing code to be interpreted and executed as input, and you can also provide it with dictionaries that replace the usual local and global scopes of variables. Maybe Node has something like that...
Also asked this question. At the moment, I myself am inclined to believe that using ORM seems to be more convenient to work with links for models (1-1, 1-M, MM). Part of the work ORM takes over.
But personally, I did not understand how to properly embed models in my classes, how to correctly match all model fields with the corresponding fields of my classes in js or typescript.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question