Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Mapping rows returned from a query onto typesafe objects is okay, but doesn't require an ORM. It's quite literally just making sure each row:

1) Has the correct native type

2) Can be accessed by name

Many normal database APIs do that themselves. I guess there's a little bit more for writes.

The point of ORMs is that they generally map objects onto tables. You create a class, and the ORM will create the database table for you based on what you have in the class. For example, for Django, you write:

   class Blog(models.Model):
       name = models.CharField(max_length=100)
       tagline = models.TextField()

       def __str__(self):
           return self.name
(source: https://docs.djangoproject.com/en/5.0/topics/db/queries/)

And it will make the table for you. If you change the class, it will make the migration for you. That's clean, simple, and easy if you're not doing anything complex. It saves a ton of work.

However, this is a Very Bad Idea for complex systems, since exactly as you point out, there shouldn't be a 1:1 mapping between tables and classes. There may very well be a 1:1 or many:1 mapping between queries and classes. More sophisticated ORMs can do a bit of that, but at some point, you run into the equivalent of Greenspun's Tenth Rule, where the ORM turns into a more complex, buggy version of SQL.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: