SQLAlchemy: The BEST SQL Database Library in Python

preview_player
Показать описание
Ever heard of SQLAlchemy and thought it sounded like a medieval potion? Well, it's not! 🧙‍♂️🔮 SQLAlchemy combines the robustness of SQL with Python's flexibility, making database management not just easier, but kinda fun too! In this video, I’ll take a closer look at this awesome tool.



🎓 Courses:

👍 If you enjoyed this content, give this video a like. If you want to watch more of my upcoming videos, consider subscribing to my channel!

Social channels:

👀 Code reviewers:
- Yoriz
- Ryan Laursen
- Dale Hagglund
- Kit Hygh
- Alexander Milden
- Bean

🔖 Chapters:
0:00 Intro
1:30 Functional Approach
5:04 Object-Oriented Approach
8:35 Relationships
10:26 Oso
12:18 Relationships part 2
16:02 Outro

#arjancodes #softwaredesign #python

DISCLAIMER - The links in this description might be affiliate links. If you purchase a product or service through one of those links, I may receive a small commission. There is no additional charge to you. Thanks for supporting my channel so I can continue to provide you with free content each week!
Рекомендации по теме
Комментарии
Автор

The documentation of sqlalghemy is a pain in the ass

hendrikmartina
Автор

"SQLAlchemy mixes SQL with questionable medieval practices" I think is the best description of the library to date!

UNgineering
Автор

When following the Domain Driven Design principals make sure your SQLAlchemy models don't become your domain models. Keep the infrastructure separated from your business logic. When you know how to write an SQL query, I find it easier to just use an SQL query builder instead of an ORM. When the record is mapped to a dataclass, it's easy to build your domain objects with a mapper.

FrankyBraem
Автор

Great overview as usual! Thanks Arjan. I just want to share my pain learning SQLAlchemy while building a production saas app with SQLModel. Especially mentioned CASCADE option, M2M relations etc. Mostly because both SQLModel and underlying SQLAlchemy evolved significantly during last years.

vlntsolo
Автор

Thank you so much Arjan..I can't wait for your next exciting videos😃❤

__mostafa__
Автор

I have been using sqlalchemy core (no OR/M) for a couple of years. Version 2 is awesome! The API is almost identical to the OR/M API. Coupled with autoload schema discovery and fluent API to construct queries and DML statements leads to very short and maintainable Repository implementations.

Note that usage of OR/M should be justified on a case by case basis; and not just assumed. My starting assumption is to NOT use an OR/M.

OR/M's are NOT as simple as they seem on the surface and can create more architectural problems than they solve. Note that is true in general and is not specific to sqlalchemy or Python. I have fought with OR/M's with Java, .NET, and C++ - as well as Python and JavaScript. Same story every time. Just avoid them.

Note in the many projects I have led we do not allow any embedded SQL. It just creates tons of work later when the product needs to move vendors - e.g., Oracle or MS SQL Server to Postgres SQL. It also unnecessarily complicates local testing with sqlite.

klmcwhirter
Автор

You just made this video with me just being tasked to create a flask graphql API with sqlalchemy. Thx a lot.😂

bryanmurasira
Автор

Arjen, when you specify the primary_key=True, you dont need to say index=True and unique=True since that is implicit in primary keys.

PedigreeGuitars
Автор

This is a great video! I've dabbled in sqlalchemy a bit but for most projects I work on I just write the SQL queries. If I need multiple queries or long queries, I store them as f-strings in a separate py file and import them as needed which helps keep my main file clean.

sk
Автор

I don't understand how, i keep making a new project, i'm looking into something, and you ALWAYS release a video about it
thanks

hugofenosoa
Автор

Great video! I was investigating using SQLAlchemy with Alembic in one of my projects, and this video came just in time to show me how to simply use SQLAlchemy! I would love to see the combo SQLAlchemy + Alembic in one of your videos too.

pedrenriquegg
Автор

I like SQLAlchemy. But for big/complex projects, I would use Django so that many features are already included such as database migrations, graphic interface to manage the database contents.

pacersgo
Автор

Could you make a video FastAPI + SQLModel ?

mathyeu
Автор

Thank you. Great presentation. Of course it's up to developer to choose approach. Medieval would be to keep database structure as separate area managed by db tools and access to data as another area this time in programming language by creating kinda DAO layer under which might be a set of sql statements :) But sqlAlchemy is absolutely wonderful.

zbyszeks
Автор

SQLAlchemy really awesome library for FastAPI at least, but its documentation is so hard to read and understand for me! Thank you for this video, Arjan. I have found some interesting things about the library in the video I didn't know before 🙂

MrVernuk
Автор

Another great video! Thanks, Arjan!
I've studying SQL Alchemy + Flask. As a lot of guys already said in the comments, the documentation of SQL Alchemy is not so friendly for noobs!!

raphaelprates
Автор

Hi Arjen, I experience relatively slow performance (minutes to insert just a couple of thousand rows) when using the execute statement. Is this typical for SQLalchemy or is it more likely the cause can be found somewhere else ?

jeroenverboom
Автор

i used ORM in Django, which i didn't really understand at first as a SQL guy.
Now with my joined young Software ingenieur we developed a big project with docker and APIs and have now a very flexible backend.

I can all beginners suggest to learn and start with ORM.

luricci
Автор

would love to see a deep dive into using oso

MicheleHjorleifsson
Автор

The only thing I am feeling bit hard about sql-alchemy is that, maintaining circular M2M relationship between models. Even some tips from documentation will not work in some circular M2M cases.

SuperHardik