Hello,

I have an augmented type that holds data for a movie's timecode, which has the format "00:00:00:00" (hours:minutes:seconds:frame) and is serialized as a CHAR:


class Timecode(TypeDecorator):

    impl = CHAR

    def load_dialect_impl(self, dialect):
        return dialect.type_descriptor(CHAR(11))

    def process_bind_param(self, value, dialect):
        if value:
            if isinstance(value, TC):
                return str(value)
            else:
                raise TypeError
        else:
            return None

    def process_result_value(self, value, dialect):
        if value:
            return TC(tcString=value)
        else:
            return None

This type works together with the TC class which allows to do computations on timecodes returned from the database. To keep this question simple lets just assume all it does is pass through a string:

class TC(object):

    def __init__(self, tcString):
        self.tcString = tcString
        #parse string here and tokenize into hrs:min:sec:frm

    def __str__(self):
        return self.tc

    #other methods here

Now I would like to be able to do the following:

s.query(Foo).update({"some_timecode": Foo.some_timecode.add_hours(5)}) # Adds 5 hours to every Foo's timecode

I have seen this should be possible with a Comparator factory in 0.8 but I am stuck with 0.7 for now. How can I do this with 0.7?

Something like this would also be OK for me:

s.query(Foo).update({"some_timecode": Foo.some_timecode + TC("01:00:00:00:00")})

I have tried implementing the __add__ for both the TC and Timecode class and read the "Augmenting Existing Types" help, but failed to put the puzzle together.

Thank you for helping!

Sebastian

--
check out www.pointcloud9.com

Sebastian Elsner - Pipeline Technical Director - RISE

t: +49 30 20180300 flor...@risefx.com
f: +49 30 61651074 www.risefx.com

RISE FX GmbH
Schlesische Strasse 28, Aufgang B, 10997 Berlin
c/o action concept, An der Hasenkaule 1-7, 50354 Hürth
Geschaeftsfuehrer: Sven Pannicke, Robert Pinnow
Handelsregister Berlin HRB 106667 B

--
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to