Wednesday, 1 April 2020

Been using NodeJs for years. Setting up Databases and ORMs still scare the shit out of me. [RANT]

TLDR: Guy doesn't know how to setup a local SQL database in a Node project where he can quickly create (or model) Tables and do CRUD.Full Story:I consider myself to well rehearsed in JavaScript. From variables and lexical scopes to closures and asynchronousity, I enjoy JavaScript a lot and I leverage it to my advantage. But, boy do I stress about setting up basic API's and doing shit like CRUD.I usually like to start from scratch, because when I use generators or scaffolds, I end up with a whole bunch of shit and some engine template engines and nonsense I don't know what to do with. Then, when it comes to setting up the database and stuff, I don't know a sane way to do this. If I wanna use MySQL or Postgres there seems to be no standard way of doing this. Rails used to have an database.yml file and the database name, user, password was defined, but I haven't seen anyone in the NodeJs community try it, and I don't have the confidence to attempt it myself.Furthermore, when you look at tutorials, everyone uses Mongo + Mongoose (whose ODM I actually like) but I want to use SQL database, and nobody ever wants to cover the atrocious database configuration in their shitty medium article for some reason.Then, I've come across some ORM's that actually do help with the config. TypeORM has a (once again, it's a generator: typeorm init --name MyProject --database mysql but I guess I'll just take up the ass this time). It actually looks promising, I don't think I have anything bad to say; it would be nice if it could to something like verse.chapter (assoications, ActiveRecord style***)*** straight out the box, but it seems like I can only verse.name after I set something up with TypeScript.The reason I like ORM's is because to me, they make sense. I know exactly what composition.verses is going to give me. Let me load the chapter 15, oh damn, I need get Chapter.find_by(number: 15) and then fetch it's .compositions.sort(order_number). Also, because it makes it easy to model your table and add relationships.​Example model of some tables:sections: ID...chapters: ID, section_id, number, namecompositions: ID, chapter_id, order_numberverses: ID, chapter_id, composition_id, namelines: ID, chapter_id, composition_id, content​Sorry for the rant, I just though I let this out. I just feel like a complete failure. I've been using this for so long and I can't do this yet. I am seeking advice or perhaps a paradigm shift in the way I approach this problem. Thank you.

Submitted April 02, 2020 at 12:20AM by praysthelord1

No comments:

Post a Comment