Best way to inplace alter a list going into postgres

Ben Finney ben+python at benfinney.id.au
Tue May 31 01:52:03 EDT 2016


Sayth Renshaw <flebber.crue at gmail.com> writes:

> Ah so I should create a function that processes and modifies in the
> middle of the process between obtaining and committing.

Separating the tasks:

* Get the data from the database, into a form useful inside your
  program. (For a Python program manipulating records from a database, a
  mapping is best because you'll be referring to fields by name.)

* Serialise the altered data back to the database. How you do this
  depends on what the program expects for a database API; my general
  recommendation is, don't re-invent the wheel.

> Or if I need to do this and more processing should I be using
> something like sqlalchemy or peewee
> http://docs.peewee-orm.com/en/latest/ ?

SQLAlchemy is certainly worth learning, so that you can decide when its
power and complexity are needed.

I'm not familiar with Peewee.

If you find that you are writing a lot of code just to handle the
interface between the database and the Python program, definitely use
SQLAlchemy or something like it, that's what they are for.

-- 
 \           “Value your freedom or you will lose it, teaches history. |
  `\     “Don't bother us with politics,” respond those who don't want |
_o__)                            to learn.” —Richard M. Stallman, 2002 |
Ben Finney




More information about the Python-list mailing list