Earlier quoted context omitted.
I've used SQLalchemy a lot. I've even written a keyset paging extension for SQLalchemy. But recently I've switched to writing stored procedures and calling them directly, instead of going through an ORM for everything... And it's so much easier.
Keeping logic in the database like that means you can’t version those procedures alongside the rest of your code. That’s a pretty big downside.
What ORMs have taught me: just learn SQL (2014)
41–50 of 360 posts
Re: What ORMs have taught me: just learn SQL (2014)
#42It depends on what you're after. I'm very comfortable in SQL, and would prefer to write my queries. But our team has grown, and we've found that developers say they know SQL, but they really don't. In general, I've found that it's not the syntax that messes people up. There's a significant mental "jump" between the usual procedural coding paradigm and the "set based" paradigm offered by SQL. Some people just never ca…
Re: What ORMs have taught me: just learn SQL (2014)
#43If this person spent all that time using Hibernate and then SQLAlchemy, and all that time did not know SQL, then their suffering and bad experiences make complete sense. You absolutely need to know SQL if you're going to use an ORM effectively. Good ORMs are there to automate the repetitive tasks of composing largely boilerplate DML statements, facilitating query composition, providing abstraction for database-specific and driver-specific quirks, providing patterns to map object graphs to relational graphs, and marshaling rows between your object model and database rows - that last one is something your application needs to do whether or not you write raw SQL, so you'll end up inventing that part yourself without an ORM (I recommend doing so, on a less critical project, to learn the kinds of issues that present themselves). None of those things should be about "hiding SQL", and you need to learn SQL first before you work with an ORM.
Re: What ORMs have taught me: just learn SQL (2014)
#44Object -relational mapping is in many cases an excessively leaky abstraction. I try keep away from it. A DSL for writing SQL in a nice, composable way is a useful thing. Some libraries, like SQLAlchemy, provide both levels, not insisting on using the object mapper.
SQLalchemy is kind of a pain in the ass to actually use, though. The DSL doesn't feel very Pythonic, it's weird and confusing. The way it traverses the Object graph when loading associations between models is magical and opaque and I could never predict when it was going to automatically work and when it wouldn't. I actually would rather be writing Ruby on Rails, because it's _less magic_ than SQLalchemy.
Re: What ORMs have taught me: just learn SQL (2014)
#45I'd rather learn the ins and outs, problems and issues, highs and lows, of SQL rather than an ORM. ORM require just as much investment in time and even then you still need to learn the sql to get the ORM to do what you want it to do. SQLAlchemy on Python is a truly fine piece of software but in the end it was much simpler and felt more powerful for me to write the SQL. And not even hard BTW. I only have a limited amo…
But you don't always get to pick what code you'll be working with and if you are working with others in a web framework pretty good chance you'll be learning an ORM anyway.
Also really long SQL statements are no fun. Like debugging a whole program written in one line. I think sometimes there is a temptation to get excessively clever with SQL.
Re: What ORMs have taught me: just learn SQL (2014)
#46> ORMs, however, encourage this use and often make writing precise projections as tedious as they are in SQL. "As tedious as SQL" is not an argument to use SQL instead.
Re: What ORMs have taught me: just learn SQL (2014)
#47An ORM turns your result into a collection of objects. THAT is what an ORM is for and about.
The fact that they are built on top of query builders and lighten the load when developing is just a handy side effect.
Re: What ORMs have taught me: just learn SQL (2014)
#48Why are we even having this debate? There are some ORMs that bring so much value to the table that you'd be stupid not to use them. Example being Django's ORM or SqlAlchemy. Also be specific in what ORM you are comparing to raw SQL. Are you talking about Hibernate or SQLAlchemy. Are you talking about a query builder? Good ORMs help tremendously with maintainability and security. They also let you drop down to raw SQL…
I've used SQLalchemy a lot. I've even written a keyset paging extension for SQLalchemy. But recently I've switched to writing stored procedures and calling them directly, instead of going through an ORM for everything... And it's so much easier.
Re: What ORMs have taught me: just learn SQL (2014)
#49Earlier quoted context omitted.
Keeping logic in the database like that means you can’t version those procedures alongside the rest of your code. That’s a pretty big downside.
I mean you could, but it’d need to be through some kind of migration system to update it.
Re: What ORMs have taught me: just learn SQL (2014)
#50I don't hear people complaining about say LINQ. Maybe it's just that your language and/or ORM or integration thereof suck?
LINQ isn't a ORM. I assume you mean Entity Framework? EF definitely has the foreign key issue. We have around a thousand tables, we tried to generate the classes for all of them including foreign keys, problem is that when you create a context that references even only a single table, it will load everything that is foreign keyed including siblings of siblings of siblings, until you run out of memory. Only way around…
This is a common theme I've seen with people blaming ORM's for being slow, it's the devs not using them appropriately more than the ORM's themselves. Not to say that they don't have their own issues.