Re: [SQLObject] PATCH: adds support for an interval timedelta column
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Matthew W. <ma...@tp...> - 2009-05-13 20:05:50
|
On Wed 13 May 2009 03:39:01 PM EDT, Oleg Broytmann wrote: > On Wed, May 13, 2009 at 07:11:22PM +0000, Matthew Wilson wrote: >> Hi -- I wrote some code to add a TimedeltaCol type. I only tested it in >> postgresql. > > Thank you! > >> +def TimedeltaConverter(value, db): >> + >> + return """INTERVAL '%d days %d seconds'""" % \ >> + (value.days, value.seconds) >> + >> +registerConverter(datetime.timedelta, TimedeltaConverter) > > The syntax is only valid in Postgres, so it has to be protected: > > def TimedeltaConverter(value, db): > if db == 'postgres': > return """INTERVAL '%d days %d seconds'""" % \ > (value.days, value.seconds) > else: > raise ValueError('TimedeltaCol is only implemented for Postgres') > >> +class TimedeltaValidator(validators.Validator): >> + def to_python(self, value, state): >> + return value >> + >> + def from_python(self, value, state): >> + return value > > Why empty validator? > > IWBN to have a test also. I completely agree; can you point me to where in the code I should write the test? Also, are there any tests I can use as a guide? Later this week, I'll try to send in an updated patch with the code you added and a test. Matt |