Changeset 841 for trunk/pgdb.py


Ignore:
Timestamp:
Feb 8, 2016, 3:05:37 PM (4 years ago)
Author:
cito
Message:

Add type helper for UUIDs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pgdb.py

    r840 r841  
    7373from time import localtime
    7474from decimal import Decimal
    75 from uuid import UUID
     75from uuid import UUID as Uuid
    7676from math import isnan, isinf
    7777from collections import namedtuple
     
    397397        'time': cast_time, 'timetz': cast_timetz,
    398398        'timestamp': cast_timestamp, 'timestamptz': cast_timestamptz,
    399         'int2vector': cast_int2vector, 'uuid': UUID,
     399        'int2vector': cast_int2vector, 'uuid': Uuid,
    400400        'anyarray': cast_array, 'record': cast_record}
    401401
     
    733733        if value is None:
    734734            return 'NULL'
    735         if isinstance(value, (Hstore, Json, UUID)):
     735        if isinstance(value, (Hstore, Json)):
    736736            value = str(value)
    737737        if isinstance(value, basestring):
     
    763763        if isinstance(value, timedelta):
    764764            return "'%s'::interval" % value
     765        if isinstance(value, Uuid):
     766            return "'%s'::uuid" % value
    765767        if isinstance(value, list):
    766768            # Quote value as an ARRAY constructor. This is better than using
     
    15271529TIMESTAMP = Type('timestamp timestamptz')
    15281530INTERVAL = Type('interval')
     1531UUID = Type('uuid')
    15291532HSTORE = Type('hstore')
    15301533JSON = Type('json jsonb')
     
    15821585    return timedelta(days, hours=hours, minutes=minutes, seconds=seconds,
    15831586        microseconds=microseconds)
     1587
     1588
     1589Uuid = Uuid  # Construct an object holding a UUID value
    15841590
    15851591
Note: See TracChangeset for help on using the changeset viewer.