On Monday, 29 July 2013 20:48:57 UTC-4, Matthew Pounsett wrote:
>
> I think I understand the mechanism here... except that since this isn't a
> real type (there's no data store behind this) is process_bind_param()
> useful at all?
>
To answer my own question... yes, of course it does because it needs to
convert to the database (or hybrid property) type in order to run the query
in the first place.
I wound up with this, which works perfectly:
class TimedeltaType(types.TypeDecorator):
impl = types.Integer
def process_bind_param(self, value, dialect):
return value.total_seconds()
def process_result_value(self, value, dialect):
return timedelta(seconds=value)
And later...
@hybrid_property
def duration(self):
if self.finish:
return self.finish - self.start
else:
return timedelta(0)
@duration.expression
def duration(cls):
return type_coerce(
func.strftime('%s', func.coalesce(cls.finish, cls.start)) -
func.strftime('%s', cls.start),
TimedeltaType
)
Thanks again for the help!
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.