3 ms·
I don't have a ton of experience with ORM, but I've always wondered how much time is saved trying to abstract SQL queries away from SQL when SQL is supposed to
by jwingy 15y ago
I don't have a ton of experience with ORM, but I've always wondered how much time is saved trying to abstract SQL queries away from SQL when SQL is supposed to be relatively easy for most people to get into. At least for the simple use cases that ORM is supposed to be good at, the SQL equivalent should be simple as well right? Or am I not quite understanding the benefits of ORM?
- jawher 15y agoIt's not just the SQL. There's also the mapping code between your objects and the SQL. for instance, for a select query: select first_name, last_name, login, email from users where id = 5; Depending on the language and ORM you use, you'll need to write code that resembles this: result = execute(query); User u = new User(); u.firstName = result.get("first_name); u.lastName = result.get("last_name); u.login = result.get("login); u.email = result.get("email); The mapping part may also involve data conversion between SQL types and you language types. The same also applies to the other direction: when you want to generate an SQL query that updates/inserts an object of yours into the database. ORMs also handle (I didn't say well) relations between objects (1..1, 1..n, n..n).