Great example from Anthony showing how easy it is to practice building database orm models and playing with them in a repl. This is good practice even if you are in a big code base to be able to test and learn in a simplified code base that does not have a mountain of other code around atuh, permissions, security, and other complex things that come into real production code bases that might make it hard to focus on what you are trying to do. Note Anthony uses backref here, thats legacy, use back_populates on both parent and child.
Posts tagged: sqlalchemy
All posts with the tag "sqlalchemy"
5 posts
latest post 2024-03-06
Publishing rhythm
External Link stackoverflow.com Today I came across some sqlalchemy models that created some relationships, some used some used. I was stumped why, I had never came accross before and I felt skill issues sinking in. backref is considered legacy # https://docs.sqlalchemy.org/en/14/orm/backref.html As stated in the sqlalchemy docs, backref is a legacy feature. Its shorthand to creating relationships between parent and child, but only adding it to the parent. While this is simpler it introduces some invisible magic.
Read a Range of Data - LIMIT and OFFSET - SQLModel SQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness. sqlmodel.tiangolo.com Today I was running some sqlmodel queries through the sqlalchemy orm. Admittedly I’ve not done enough orm queries before, and I’ve done quite a bit of raw sql. I was trying to get objects from two separate models that had relationships setup. It is incredibly slow, and gives me the following warning. What I learned from the SQLModel docs is that you should give it a join to correct this and go much faster.
External Link stackoverflow.com How to sort results from a sqlalchemy based orm. I needed this to enable paging on my thoughts api.
Column INSERT/UPDATE Defaults — SQLAlchemy 1.4 Documentation docs.sqlalchemy.org sqlalchemy server_defaults end up as defaults in the database when new values are inserted.