[Python-ideas] Add recordlcass to collections module

Jacco van Dorp j.van.dorp at deonet.nl
Mon Sep 3 03:23:59 EDT 2018


This feels really useful to me to make some quick changes to a database -
perhaps a database layer could return an class of type Recordclass, and
then you just simply mutate it and shove it back into the database.
Pseudocode:

record = database.execute("SELECT * FROM mytable WHERE primary_key = 15")
record.mostRecentLoggedInTime = time.time()
database.execute(f"UPDATE mytable SET mostRecentLoggedInTime =
{record.mostRecentLoggedInTime} WHERE primary_key = {record.primary_key}":)

Or any smart database wrapper might just go:

database.updateOrInsert(table = mytable, record = record)

And be smart enough to figure out that we already have a primary key
unequal to some sentinel value like None, and do an update, while it could
do an insert if the primary key WAS some kind of sentinel value.

which is something I really wanted to do in the past with namedTuples, but
had to use dicts for instead.

Also, it's rather clear that namedList is a really bad name for a
Recordclass. It's cleary not intended to be a list. It's a record you can
take out from somewhere, mutate, and push back in. We often use namedTuples
as records now, but we can't just mutate those to shove them back in - you
have to make new ones, and unless you write a smart wrapper for database
handling yourself, you can't just shove them in either. Recordclass could
be the gateway drug to a smart database access layer that reduces the
amount of SQL we need to write - and that's a good thing in my opinion.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180903/add8ec1d/attachment.html>


More information about the Python-ideas mailing list