News for hackers. Stuff that matters.
Re:Node.js 16 Available Now by camjohnson26 on Tuesday April 20, 2021 @02:20PM (#26878692)
I’ve got a similar stack, what are you using for ORM? Started using Prisma to replace TypeORM/TypeGraphQL but it’s new and unproven. Also are you caching with Redis, any other utilities helping with that? GraphQL-codegen is a lifesaver for generating gql types and resolvers.
Re:Node.js 16 Available Now by hn_throwaway_99 on Tuesday April 20, 2021 @02:47PM (#26879304)
We are not using an ORM. I am a pretty strong advocate against ORMs, but that is a topic for a different discussion. We have a set of DAO components that access the DB using Slonik, https://github.com/gajus/slonik (overview explaining the rationale for this library is at https://medium.com/@gajus/bf410349856c ).

Our app doesn't have a huge need for caching, but we use a mix of in-server-memory caching ( https://github.com/isaacs/node-lru-cache ) and Redis when we need a global cache.

Re:Node.js 16 Available Now by tolmasky on Tuesday April 20, 2021 @03:02PM (#26879655)
I highly recommend you not use node-lru-cache: https://github.com/isaacs/node-lru-cache/issues/63 (as you can see from the last comment on that bug, these truly bizarre performance characteristics were not solved, and I would recommend drop-in replacing the fast-lru library we use).
Re:Node.js 16 Available Now by sthomas1618 on Tuesday April 20, 2021 @05:13PM (#26881772)
I've worked worked developers that have a hardline against ORMs. I see lot of their points, especially around the performance of raw SQL. But I cannot get past how much boilerplate code that has be written over and over again. And then you have to test that boilerplate code. I find that most people are far more productive using an ORMs. To me this makes sense because it's less things to type. Less is often more.

We have services that don't ORMs and I have to wonder if it's worth the cost.

Re:Node.js 16 Available Now by hn_throwaway_99 on Wednesday April 21, 2021 @09:49AM (#26889654)
While I don't write a ton of "boilerplate", the primary thing for me is writing boilerplate, if necessary, is trivially easy. What's hard is debugging when problems arise, or trying to do some slightly more complicated join that isn't supported out of the box by your ORM tool of choice.

Basically, in my opinion ORMs just make the easy stuff slightly easier, but they make the hard stuff much harder, and when you're stressed out trying to fix some critical production DB query all they do is get in the way.

Re:Node.js 16 Available Now by hermanradtke on Tuesday April 20, 2021 @06:03PM (#26882428)
We use slonik and a few helper functions. Very little boilerplate.
Re:Node.js 16 Available Now by btown on Tuesday April 20, 2021 @03:50PM (#26880495)
I'm curious how you handle migrations and schema documentation, which to me are the huge benefit of using something like Django or ActiveRecord. Do you version-control at least your forward-migrations as SQL or SQL-via-Slonik? And do you have processes in place to ensure columns are documented in a central location?
Re:Node.js 16 Available Now by hn_throwaway_99 on Wednesday April 21, 2021 @09:44AM (#26889586)
For migrations we actually use knex, but primarily just because it was in place first before I knew about Slonik.

Writing a migration tool is pretty trivially easy - all knex does is let you write an up migration and a down migration, and it keeps track of which migrations have been applied in a DB table. Main thing is that all of our migrations are each in an individual versioned file in our source repo.

We use postgres COMMENT functionality to apply comments to all of our table columns.

Re:Node.js 16 Available Now by eyelidlessness on Tuesday April 20, 2021 @04:52PM (#26881494)
If you’re already doing codegen, you might take a look at Zapatos[1]. It generates types from your database schema, and provides type safe query builders (raw SQL via tagged literal, some simple ORM-like functions for basics).

1: https://jawj.github.io/zapatos/

Re:Node.js 16 Available Now by camjohnson26 on Tuesday April 20, 2021 @05:57PM (#26882378)
Prisma does something similar, provides a typed schema and a query engine written in Rust.
Re:Node.js 16 Available Now by notsag-hn on Tuesday April 20, 2021 @03:42PM (#26880367)
Maybe not an ORM but a query builder: Knex has been of so much help to me, it works pretty well and it's really easy to use. Used sequelize in the past but it can get incredibly complicated, really positive change.
Re:Node.js 16 Available Now by coldtea on Tuesday April 20, 2021 @03:05PM (#26879716)
ORM? What is this, 2004 J2EE?

Joking aside, in a dynamic language like Javascript, especially in modern coding style which is not OO anyway, you don't need an ORM.

Re:Node.js 16 Available Now by tayo42 on Tuesday April 20, 2021 @05:03PM (#26881638)
You write sql statements? And turn the response into classes by hand in every app you write? Ruby and python have orms too. Am I missing something?
Re:Node.js 16 Available Now by coldtea on Tuesday April 20, 2021 @06:10PM (#26882508)
You write classes? What is this, 2005?

Joking aside, I do write SQL statements (or use a query builder, which is not the same as an ORM).

I don't "turn the response into classes by hand in every app I write" however, because the responses are perfectly usable as they are (in a more functional style), and OO is not the best way to model records anyway.

I know Ruby and Python have ORMs, ActiveRecord, SQLAlchemy and so on. They're not really needed. Heck, I've read authors of ORMs saying you don't really need one...

Re:Node.js 16 Available Now by tayo42 on Tuesday April 20, 2021 @06:34PM (#26882803)
This seems like a sweeping judgment your making saying don't use orms, or classes. But this seems like just an odd religious take people have so I'm out...
Re:Node.js 16 Available Now by whatl3y on Wednesday April 21, 2021 @07:33AM (#26888203)
While some people are hard lined enough on this that I agree it sort of becomes weird, I can tell you my beef with ORMs comes from being burned before a couple of times by a super inefficient aggregation ActiveRecord did on GROUP BY queries that it 1. not only took a really long time to figure out why a particular page in our app was loading slow but 2. we ended up having to write raw SQL to fix it.

I think the answer depends on the type and load/volume of app you're working with combined with the dynamics, size, and skill level of your team(s). I'm extremely comfortable writing, profiling, query planning, and debugging SQL queries. Others aren't, and therefore having an ORM to query data in the DB with the syntax of the language you're using in your projects makes way more sense, if nothing other in order to speed your team up.

Re:Node.js 16 Available Now by tayo42 on Wednesday April 21, 2021 @05:59PM (#26895972)
I think the mistake is thinking an orm is actually going let you be free of knowing or caring database fundamentals. That only applies in the most simple cases. An orm has other benefits though.
Re:Node.js 16 Available Now by scrollaway on Wednesday April 21, 2021 @07:03AM (#26887913)
How much work do you have to deal with if a column gets renamed? Be honest.
Re:Node.js 16 Available Now by whatl3y on Wednesday April 21, 2021 @07:28AM (#26888151)
1. Don't rename your columns, but if you have to

2. project search and replace on $COLUMN_NAME

If your column name is a common keyword, variable name, etc. in your code base and it's difficult to find using project search, that's unfortunate, but we organize our backend code and tests in a logical enough way that it's never taken longer than an hour to create a PR to create a migration to rename a column and update all places in code that reference it.

Re:Node.js 16 Available Now by scrollaway on Wednesday April 21, 2021 @08:38AM (#26888834)
Renaming a column is an operation which showcases the weakness in not using an ORM. Other operations of the sort do exist, anything that operates on columns across multiple arbitrary spots in the code.

IMO an hour for a change you have so little confidence about is not acceptable when the alternative allows you to do it in a second with full confidence.

Re:Node.js 16 Available Now by whatl3y on Wednesday April 21, 2021 @08:49AM (#26888946)
While this is fair and I don't disagree that changing a column name or possibly other schema changes using an ORM and it's subsequent migration scripts is potentially going to be a faster exercise than without one, changing a column name (or any schema change for that matter) in a database in my experience is rare. If you choose to use an ORM for reasons like it might (emphasis on might) be a bit faster and easier to change a column name than without one instead of for other more meaningful people or efficiency-oriented reasons of the day-to-day developer workflow is probably a poor approach.

Keep in mind I've installed and used an ORM in projects where the ORM is used only for migrations, but not used in application code and this is absolutely a fine reason to use one imo. But adopting an ORM for migration purposes and forcing or using in application code simply because it's installed isn't necessarily a good approach.

Re:Node.js 16 Available Now by scrollaway on Wednesday April 21, 2021 @09:12AM (#26889202)
Like I said, it's one example.

ORMs are to SQL what static types are to programming languages. The conversation we just had was me giving you one example of the benefit of static types, which happens to showcase a huge weakness in dynamic typing:

- How painful is it to rename a class attribute?

=> It's a long search & replace exercise which results in a less-than-certain outcome.

The obvious take from this isn't that "renaming class attributes is rare".

Re:Node.js 16 Available Now by LunaSea on Wednesday April 21, 2021 @02:54PM (#26893956)
This is a very simplistic view of the situation.

ORMs have very basic support of current SQL standards and database specific features.

This means that using an ORM reduces the power of the database choice you made.

Also things like arbitrary SQL support imply you have to manually creat return value typings.

Having to leave the nice ORM wrapper functions for arbitrary SQL means you lose all the ORM niceties like soft deleted or updated_at fields

Overall I see very little use for ORMs.

Re:Node.js 16 Available Now by gmac on Wednesday April 21, 2021 @02:56AM (#26886216)
You don’t need an ORM, but (unless you’re a total masochist) you probably want _something_ to smooth the interaction with SQL.

We have a TypeScript Node.js API in production, and we wrote Zapatos to be that something: https://jawj.github.io/zapatos/