Abstraction level at which to create SQLAlchemy ORM object

Loris Bennett loris.bennett at fu-berlin.de
Thu Feb 10 08:14:30 EST 2022


Hi,

I am writing a command line program which will modify entries in a
database and am trying out SQLAlchemy.

A typical command might look like

  um --operation add --uid ada --gid coders --lang en

Parsing the arguments I get, ignoring the operation, a dict

  {uid: "ada", gid: "coders", lang: "en"}

At some point this needs to be converted into an object of the class User:

  class User(Base):
      __tablename__ = "users"

      uid = Column('uid', String, primary_key=True)
      gid = Column('gid', String)
      lang = Column('lang', String)

In a way it seems it would be economical to do the conversion as early
as possible, so I can just pass around User objects.  However, this
would mean that the entry point for the program would already be tightly
coupled to the specifics of the database interaction.  

On the other hand, delaying the conversion would mean probably having to
define my own User class, which seems like unnecessary overhead.  It
would have the advantage that I could ditch SQLAlchemy more easily if I
find it too mind-bending.

WDYT?

Cheers,

Loris

-- 
This signature is currently under construction.


More information about the Python-list mailing list