Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Why don't just use SQL without an ORM?
I tried it out and I thought the process was much simpler, especially after learning the SQL syntax in a couple of the previous videos in the full-stack course, just curious as I don't see so much advantages using a ORM if you like writing SQL.
Anna Pichugina25,266 Points
Totally agree with you that once you get the hang of SQL it can seem like learning an ORM is just extra work. I've been thinking about this in the context of a project at work, where we use Django and an SQL database. The nice thing about using Django ORM to interact with the database is that it'll write the sql for you and interpolate values into the query, which can get a little tricky if you're trying to do batch queries and such with raw sql and psycopg2. And it also destructures the values you get from the database so you can use them like any other python variable in your code.
The other thing Django does, which is pretty neat, is any time you change your models it'll write a migration file that documents the changes to the database and more importantly includes code to reverse the changes, which is really important for version control and if you're trying to sync changes across your local version of a project and a deployed version on a server, as well as if you want to reverse any changes down the line.
Of course Django also has a lot of built-in safety features, like it'll automatically set your tables up with unique id's which is good practice but if you're doing raw sql it's not going to stop you from setting up a table without them. I think it also automates some performance improvements in the database like indexing and vacuuming.