There are two (three, but I\'m not counting Elixir, as its not \"official\") ways to define a persisting object with SQLAlchemy:
In our team we settled on declarative syntax.
Rationale:
metadata
is trivial to get to, if needed: User.metadata
.User
class, by virtue of subclassing Base
, has a nice ctor that takes kwargs for all fields. Useful for testing and otherwise. E.g.: user=User(name='doe', password='42')
. So no need to write a ctor!Regarding "keeping out ORM from business view": in reality your User
class, defined in a "normal" way, gets seriously monkey-patched by SA when mapper
function has its way with it. IMHO, declarative way is more honest because it screams: "this class is used in ORM scenarios, and may not be treated just as you would treat your simple non-ORM objects".