Sunday 12 March 2017

Knex's async queries + Objection.js ORM might be killing me softly.

EDIT: I should note that I'm using postgresSo I submitted another question today before I realized the scope of what's going on here, so this is a higher level question.As I understand the point of object relational mappers, it's to work with objects and have the ORM handled the database to reflect those changes in the background. I'm coming from Rails, so something really simple, like giving a Person named Raymond a Gift of a car (inserting a row correctly into a people table, and into a gifts table, and into a join table like people_gifts), could be done like this:raymond = Person.create({name: "Raymond"}) car = Gift.create({type: car}) raymond.receive(car) // assuming an instance method called receive and the tables/columns etc The Rails ORM in this instance makes it really easy for me to establish relations between tables. In fact I don't have to. I manage relations at the object's instance and class levels and the ORM does the rest.So now I'm learning Node and I see that the way to get your migrations and your query engine and you ORM all set up is Knex + Objection and I do it.But now I want to accomplish the above in Node and the two ways I've seen to do this here are either nested callbacks which feels like hell and then I found the term "callback hell", or use asyncawait or the es7 equivalent which actually ends up being even more complicated because I'm constantly making suspendible functions and suspending them on inner synchronous ones. Either way things get nested and ridiculous but that's not even my issue. My issue is that if you're going to be doing all this, then you're not really working with Models at all really. It defeats the purpose of the ORM. If I can't do anything with my models without arranging them in a convoluted chronological order, things are really not that good.So I MUST be missing something HUGE. What is it? Things can't be this bad.

Submitted March 12, 2017 at 08:58PM by coderbee

No comments:

Post a Comment