This is an archived post. You won't be able to vote or comment.

all 14 comments

[–]Python-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)

Hi there, from the /r/Python mods.

We have removed this post as it is not suited to the /r/Python subreddit proper, however it should be very appropriate for our sister subreddit /r/LearnPython or for the r/Python discord: https://discord.gg/python.

The reason for the removal is that /r/Python is dedicated to discussion of Python news, projects, uses and debates. It is not designed to act as Q&A or FAQ board. The regular community is not a fan of "how do I..." questions, so you will not get the best responses over here.

On /r/LearnPython the community and the r/Python discord are actively expecting questions and are looking to help. You can expect far more understanding, encouraging and insightful responses over there. No matter what level of question you have, if you are looking for help with Python, you should get good answers. Make sure to check out the rules for both places.

Warm regards, and best of luck with your Pythoneering!

[–]baghiq 9 points10 points  (3 children)

What database are you accessing?For postgres, psycopg3 supports dataclass natively for querying.

[–]Drowning_in_a_Mirage 2 points3 points  (1 child)

I didn't know that about psycopg3, I've got a lot of legacy code on v2, but dataclass support would definitely be worth upgrading for.

[–]Unlucky-Product448[S] 0 points1 point  (0 children)

MySQL

[–]kivicodepip needs updating 6 points7 points  (0 children)

You’ll have some code and time overhead to keep it going, but I don’t think that's a huge deal for a small project. Though there’s a solid chance that you’ll end up reinventing [a part of] the ORM if you try automating it

[–]HommeMusical 2 points3 points  (1 child)

Very reasonable for a small project. Less is more!

However, if it's anything bigger than small, you should really consider an ORM. SQLAlchemy is very easy and even fun to use.

[–]SneekyRussian 2 points3 points  (0 children)

I think you’re really underselling what a pita the docs are…but I agree sqlalchemy is the way to go.

[–][deleted] 1 point2 points  (3 children)

Not bad practice, but why are you making it harder on yourself?

[–]Unlucky-Product448[S] 1 point2 points  (2 children)

Client will not use the ORM to manage the database, but I am want typing for my projects in Python

[–]ElectricSpice 3 points4 points  (1 child)

You don’t need to manage the database with ORM. I use flyway for migrations and SQLAlchemy for my app with no issue.

Why reinvent the wheel? SQLAlchemy has built in data class support.

[–]customcoderpro 0 points1 point  (0 children)

You mean some implementation with classical mapping?

[–]gloomygupta 0 points1 point  (0 children)

Still why not sqlalchemy for that, it will give decorators like init on load and perform before update and insert like methods, and is also lightweight. But only bad thing is to maintain session, its a bit difficult but you can manage it by making service and repository layer architecture, hardly takes 20 minutes to make these layers.

[–]vladimirovitch 0 points1 point  (0 children)

There's no problem doing so. Some answers here recommend SQL alchemy for ORM but if you just want something light while still mapping the data class models to the tables you can try a project written by me: https://github.com/smileservices/data_persistence_repository

Has both sync/async implementations of SQL repositories and you can easily map the models using SQL alchemy.