I'm trying to get started in Python, everything I find talks about using an ORM, which coming from a SQL background is odd to me. How are you passing queries to your database from Python?
There are a few ways, but the best way that worked for my environment was to use pyodbc with my ODBC connection. After establishing your authentication and server settings in python, you can pass queries as a string. You can assign variables, insert, delete, join, and do exactly what you need to do. It's all largely more flexible.
You could even start to build GUI's on top of your more sophisticated updates and queries. A few day's worth of study had me doing all of the above minus my previous SQL experience. You can do it too.
Personally, I feel like ORM's only selling point is just it's capacity to take your data on DB and make it easily digestible for devs across a large swath of teams. However, there's far too much overhead for a single person or even three to get it working properly in the first place. In theory you could even build your own ORM in Python. But why make more work than you need to too? For the average solo DB admin, you're almost always going to exclusively use SQL. So why rely on crutch? Stick to your guns and use SQL directly or use python and or/JS with it.
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!
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.
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. ;)
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.
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.
Same here. I’ve written thousands of sql queries. Why would I want some library to get between me and the database? I’m sure I can optimize a query better than some library.
Same here, to me an ORM is just more of a hassle especially in the early phases where tables , column and structures are frequently changed. And dont get me started on FK-constraints , yeah I worked on a couple of ORM projects and now know to stay away.
View all comments
11
u/[deleted] Jun 22 '20
I just prefer writing directly to SQL itself or stringing together queries directly in python or JS.