Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLAlchemy and Imperative Mapping (a.k.a. Classical Mapping) #341

Open
AdrianB-sovo opened this issue Mar 2, 2023 · 3 comments
Open

SQLAlchemy and Imperative Mapping (a.k.a. Classical Mapping) #341

AdrianB-sovo opened this issue Mar 2, 2023 · 3 comments

Comments

@AdrianB-sovo
Copy link

AdrianB-sovo commented Mar 2, 2023

In chapter 02, it's stated that the classical mapping is an alternative to the declarative mapping and that:

This gives us all the benefits of SQLAlchemy

See here: https://github.com/cosmicpython/book/blob/master/chapter_02_repository.asciidoc#inverting-the-dependency-orm-depends-on-model

But, in the SQLAlchemy documentation about Imperative/Classical Mapping, the following is stated:

The imperative mapping form is a lesser-used form of mapping that originates from the very first releases of SQLAlchemy in 2006. It’s essentially a means of bypassing the Declarative system to provide a more “barebones” system of mapping, and does not offer modern features such as PEP 484 support. As such, most documentation examples use Declarative forms, and it’s recommended that new users start with Declarative Table configuration.

(Emphasis mine)

The content of this chapter should probably be modified to indicate that.
Also, is there an alternative that would use the recommended Declarative mapping?

@hjwp
Copy link
Contributor

hjwp commented May 12, 2023

as far as i know the only alternative is to have your domain model classes become sqlalchemy classes, effectively tightly coupling your domain with sqlalchemy. so as always, it's a trade-off...

@hjwp
Copy link
Contributor

hjwp commented May 12, 2023

nice to see the classical mappers still exist in v2 tho, i was worried they were gone completely. i should upgrade....

@Bryant-Yang
Copy link

The data class might be dataclass, attrs or pydantic, all are more general and framework independent, easy to write business logic with or without sqlalchemy or even relational database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants