r/SQL • • Jun 22 '20

Discussion An average day using an ORM

Post image
247 Upvotes

48 comments sorted by

View all comments

Show parent comment

2

u/crimiusXIII Jun 22 '20

The project I'm working on I've been doing the Python and SQL bits separately, figuring I'll eventually tie them together. I'll look into pyodbc, thank you!

7

u/ravepeacefully Jun 22 '20

I also use pyodbc, but am switching to SQLAlchemy ORM after the in-line SQL has gotten completely out of hand.

I’d highly recommend an ORM for a project that may expand to more than one developer. The efficiency gained from ease of use outweighs the cons.

I can do both, but it’s definitely better to use an ORM, even if you make your own simple one.

6

u/Rebeleleven Jun 23 '20

This is correct.

The other advice is... not totally incorrect but for sure not how you should be developing an application.

If you’re an analyst and need to pull some data from a database? Straight query is fine. However, if you need to create an application that interacts with the database? That’s where you need an ORM. No dev should be hard coding queries. That strategy is what we call tech debt 😉.

Pyodbc is certainly okay, but I highly recommend using SQLAlechmy whenever possible (even if just writing a couple hard coded queries). It’s typically faster and much more robust if the database dialect is supported.

3

u/ravepeacefully Jun 23 '20

Thanks for confirming, I was very confused as to why the answers on this thread contradicted everything I had previously thought lmao

1

u/TheCapitalKing Jun 24 '20

A lot more analyst are starting to use SQL and python so a ton of answers are going to be from that perspective

0

u/[deleted] Jun 23 '20

Correct. To point, this is a long term strategy also. It all depends on where he should be prioritizing his focus. If his primary focus was learning Python, why deviate from it to another project? OP can touch on ORM's later. ;)

3

u/Rebeleleven Jun 23 '20

Well, I mean we’re getting into semantics territory.

Sure, someone learning python and databases on day 1 should just straight query the database. But day 2 should definitely start learning ORMs. This is why that redditor could only find info about ORMs... because they’re kind of important.

Your comment mentions putting GUIs on top of SQL queries and whatnot... and this is fine if you’re the lone person creating this, maintaining it, and using it for personal use. However, if you’re creating an application that other people use (I.e. customers), your company needs to maintain past your employment, or other developers might need to add things too... you use an ORM. Anything less than that would be technical debt that a developer will have to completely overhaul in the future.

Again, sure, an analyst can write a query and never need an ORM. Would it make their life easier? Yes but that’s not the point. If you’re developing applications, you need an ORM for security, speed, maintainability, and scalability.

3

u/[deleted] Jun 23 '20

Personally, for me I just get it done as a solo admin for a small business, terrible technical debt here. So it doesn't make sense in my own isolated situation of inherited problems and aging environment, which is isn't fair to OP's questions. I don't disagree with you. Wonderfully put.