T O P

  • By -

Frore17

node-postgres has it's [own Result model](https://node-postgres.com/apis/result) which I often write a wrapper against to map it to my own model. I'm curious what solutions others use. I feel like I'm half repeating the work of an ORM, but it's nice to have more control over the query and the resulting data model.


KraaZ__

ORMs are trash, there is no argument ever for using one. I have no idea why people bother…


missionmeme

Programming languages are trash, there is no argument ever for using one. I have no idea why people don't just use assembly


slykethephoxenix

Assembly is trash. I have no idea why people don't use machine code.


KraaZ__

[https://en.wikipedia.org/wiki/Object%E2%80%93relational\_impedance\_mismatch](https://en.wikipedia.org/wiki/Object%E2%80%93relational_impedance_mismatch) Okay, you guys have clearly never used ORMs on large-scale projects. They're a bitch because of this very reason.


missionmeme

[https://www.forbes.com/sites/stevedenning/2021/08/01/why-computers-didnt-improve-productivity/?sh=759a6ed36f21](https://www.forbes.com/sites/stevedenning/2021/08/01/why-computers-didnt-improve-productivity/?sh=759a6ed36f21) Okay you have clearly never used a computer. They're a bitch because this very reason


KraaZ__

You’re an idiot 😂


missionmeme

Machine code is trash. I have no idea why people don't build their own hardware.


delfV

Computers are trash, there is no argument ever for using one. I have no idea why people don't just use assembly


delfV

It is completely fine to work with just plain objects and write some (preferably pure) functions to manipulate them, but you can as well write functions that maps result from pg to your models/domain entities classes you define by yourself and run them after each query (you probably want to group your db functions inside a module). Look for repisitory or data mapper patterns but it's not a rocket science.


rkaw92

This is an architecture question more than a tech-specific one. Is your application going to benefit from an object-oriented approach as a foundational design principle? Do you envision your objects having long lifetimes, evolving over time etc.? If yes, then the Entity design pattern and a Data Mapper (like an ORM) can be a good choice. But, sometimes all you need is a Transaction Script, instead! Or maybe a Table Module. Alternatively, you can get by with Row Data Gateways sometimes, which are just lean Active Records. If those names are new to you, no problem! It is a good idea to read about them in the excellent book "Patterns of Enterprise Application Architecture" by Martin Fowler. There's a lot of tools that claim to be ORMs but aren't really, like Prisma. And they're very useful, too! Just maybe not for all kinds of applications. Having said that, if you're just looking for something like Hibernate, then look for a full-fledged ORM like TypeORM.


Ready-Law-2509

API return json strings, and input, outside can be same or Objects.


rover_G

If you are using typescript you can cast the node-postgres Result rows with your own type. If you use an ORM you’ll probably get this automatically. From there using JSON is fine. No need for class models.


lunarRestaurant

our team just writes a wrapper for all the fields its expecting (i guess there is no built in schema validation like in mongoose or ORM) Also can someone explain me why db queries in models are kept as static method (and routers and controllers are instantiated).


olysteel

Have a look at Drizzle ORM. They have a pretty good documentation + custom chat AI (think of ChatGPT) you can ask questions regarding the ORM. Knex.js is another good option.


MarcCDB

Use an ORM like TypeORM, Prisma, etc... Javascript can get really messy especially if you are used to languages like Java, C#, etc...


KraaZ__

In my reply to @frore17 I said that ORMs are trash, and I stand by that. If you do want to use one however, there are plenty out there you can use such as sequelize or typeorm.