Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Everyone is entitled to an *informed* opinion." -- Harlan Ellison


devel / comp.lang.python / Abstraction level at which to create SQLAlchemy ORM object

SubjectAuthor
* Abstraction level at which to create SQLAlchemy ORM objectLoris Bennett
`* Re: Abstraction level at which to create SQLAlchemy ORM objectCameron Simpson
 `- Re: Abstraction level at which to create SQLAlchemy ORM objectLoris Bennett

1
Abstraction level at which to create SQLAlchemy ORM object

<87k0e2j22x.fsf@hornfels.zedat.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17006&group=comp.lang.python#17006

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.be...@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: Abstraction level at which to create SQLAlchemy ORM object
Date: Thu, 10 Feb 2022 14:14:30 +0100
Organization: Freie Universitaet Berlin
Lines: 40
Message-ID: <87k0e2j22x.fsf@hornfels.zedat.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: news.uni-berlin.de 8zEJzMHaNAt3P687rmOY1Ai87NXrvxNV71JeqVWAomJVPa
Cancel-Lock: sha1:M5IfnOzRIMV4m6WKMDzYPM+zXhs=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Loris Bennett - Thu, 10 Feb 2022 13:14 UTC

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.

Re: Abstraction level at which to create SQLAlchemy ORM object

<mailman.107.1644544140.7010.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17034&group=comp.lang.python#17034

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: cs...@cskk.id.au (Cameron Simpson)
Newsgroups: comp.lang.python
Subject: Re: Abstraction level at which to create SQLAlchemy ORM object
Date: Fri, 11 Feb 2022 10:59:46 +1100
Lines: 59
Message-ID: <mailman.107.1644544140.7010.python-list@python.org>
References: <87k0e2j22x.fsf@hornfels.zedat.fu-berlin.de>
<YgWm8hz5chR51d60@cskk.homeip.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: news.uni-berlin.de yp65isIyhujGT3LQ0Tp5eACDw6bbdJTZIuoGzI9iRgLg==
Return-Path: <cameron@cskk.id.au>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.003
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'skip:@ 10': 0.03; 'def':
0.04; 'class,': 0.05; 'coders': 0.05; 'ada': 0.09; 'controlled':
0.09; 'string,': 0.09; 'cheers,': 0.11; 'talks': 0.14;
'possible,': 0.15; 'arguments': 0.16; 'bennett': 0.16; 'cameron':
0.16; 'conversion': 0.16; 'dict': 0.16; 'from:addr:cs': 0.16;
'from:addr:cskk.id.au': 0.16; 'from:name:cameron simpson': 0.16;
'hand,': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'objects.':
0.16; 'received:10.10': 0.16; 'simpson': 0.16; 'subject:level':
0.16; 'subject:which': 0.16; 'tightly': 0.16; 'uid': 0.16;
'wrote:': 0.16; 'probably': 0.17; 'to:addr:python-list': 0.20;
'maybe': 0.22; 'skip:_ 10': 0.22; 'command': 0.23; "i'd": 0.24;
'seems': 0.26; 'interact': 0.26; 'object': 0.26; 'else': 0.27;
'mostly': 0.28; 'header:User-Agent:1': 0.30; 'modify': 0.31;
'program': 0.31; 'concerned': 0.32; 'manner.': 0.32; 'but': 0.32;
'core': 0.34; 'mean': 0.34; 'header:In-Reply-To:1': 0.34;
'trying': 0.35; 'close': 0.35; 'change': 0.36; 'class': 0.37;
'way': 0.38; 'could': 0.38; 'least': 0.39; 'decide': 0.39;
'methods': 0.39; 'advantage': 0.40; 'define': 0.40; 'should':
0.40; 'method': 0.61; 'above': 0.62; 'everything': 0.63; 'pass':
0.64; 'specifics': 0.64; 'your': 0.64; 'look': 0.65; 'required':
0.65; 'received:userid': 0.66; 'entire': 0.67;
'header:Received:6': 0.67; 'exactly': 0.68; 'delaying': 0.69;
'lives': 0.69; 'you.': 0.71; 'database': 0.80; 'need.': 0.84;
'converted': 0.84; 'db,': 0.84; 'switching': 0.84
X-RG-Spam: Unknown
X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedvvddriedvgdduvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfupfevtfgpvffgnffuvffttedpqfgfvfenuceurghilhhouhhtmecugedttdenucenucfjughrpeffhffvuffkgggtuggjfghfsehttdertddtredvnecuhfhrohhmpeevrghmvghrohhnucfuihhmphhsohhnuceotghssegtshhkkhdrihgurdgruheqnecuggftrfgrthhtvghrnhepleevfeeghfeggfehuddvgfehhfffjeegvdeuiefhgeelgeekfeffiefguddtveehnecukfhppedurdduvdelrddvhedtrdejjeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhephhgvlhhopegsohhrghdrtghskhhkrdhhohhmvghiphdrnhgvthdpihhnvghtpedurdduvdelrddvhedtrdejjedpmhgrihhlfhhrohhmpegtrghmvghrohhnsegtshhkkhdrihgurdgruhdpnhgspghrtghpthhtohepuddprhgtphhtthhopehphihthhhonhdqlhhishhtsehphihthhhonhdrohhrgh
X-RazorGate-Vade-Verdict: clean 0
X-RazorGate-Vade-Classification: clean
X-RG-VS-CLASS: clean
X-Authentication-Info: Submitted using ID cskk@bigpond.com
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <87k0e2j22x.fsf@hornfels.zedat.fu-berlin.de>
User-Agent: Mutt/2.1.5 (2021-12-30)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <YgWm8hz5chR51d60@cskk.homeip.net>
X-Mailman-Original-References: <87k0e2j22x.fsf@hornfels.zedat.fu-berlin.de>
 by: Cameron Simpson - Thu, 10 Feb 2022 23:59 UTC

On 10Feb2022 14:14, Loris Bennett <loris.bennett@fu-berlin.de> wrote:
>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.

If the entire persistent state of the user lives in the db I'd just
define the User ORM type and give it whatever methods you need. So
exactly what you've got above.

It is close to the db, but if you only interact via the methods and the
core attributes/columns that should be mostly irrelevant to you.

If you're concerned about switching backends, maybe define an
AbstractUser abstract class with the required methods. Then you can at
least ensure method coverage if you make another backend:

class AbstractUser(ABC):
@abstractmethod
def some_user_method(self,...):

class SQLAUser(Base, AbstractUser):
... your SQLA ORM User class above ...

User = SQLAUser

... everything else just talks about user ...

But you can do all of that _later_, only needed if you decide to change
backends in a controlled manner.

Cheers,
Cameron Simpson <cs@cskk.id.au>

Re: Abstraction level at which to create SQLAlchemy ORM object

<87leyhopcb.fsf@hornfels.zedat.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17036&group=comp.lang.python#17036

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.be...@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: Re: Abstraction level at which to create SQLAlchemy ORM object
Date: Fri, 11 Feb 2022 08:05:24 +0100
Organization: Freie Universitaet Berlin
Lines: 69
Message-ID: <87leyhopcb.fsf@hornfels.zedat.fu-berlin.de>
References: <87k0e2j22x.fsf@hornfels.zedat.fu-berlin.de>
<YgWm8hz5chR51d60@cskk.homeip.net>
<mailman.107.1644544140.7010.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: news.uni-berlin.de thFsZijccr8NS1J3raqCIA+BM6h/0o3EoTYPQFFxr5E0pn
Cancel-Lock: sha1:KZFEpntgvNyD8aJrMcPUQ0B9I/M=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Loris Bennett - Fri, 11 Feb 2022 07:05 UTC

Hi Cameron,

Cameron Simpson <cs@cskk.id.au> writes:

> On 10Feb2022 14:14, Loris Bennett <loris.bennett@fu-berlin.de> wrote:
>>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.
>
> If the entire persistent state of the user lives in the db I'd just
> define the User ORM type and give it whatever methods you need. So
> exactly what you've got above.
>
> It is close to the db, but if you only interact via the methods and the
> core attributes/columns that should be mostly irrelevant to you.
>
> If you're concerned about switching backends, maybe define an
> AbstractUser abstract class with the required methods. Then you can at
> least ensure method coverage if you make another backend:
>
> class AbstractUser(ABC):
> @abstractmethod
> def some_user_method(self,...):
>
>
> class SQLAUser(Base, AbstractUser):
> ... your SQLA ORM User class above ...
>
> User = SQLAUser
>
> ... everything else just talks about user ...
>
> But you can do all of that _later_, only needed if you decide to change
> backends in a controlled manner.

Thanks for reminding me about abstract classes, but more importantly
that I can do this kind of stuff later.

Cheers,

Loris

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor