Changeset 821 for trunk


Ignore:
Timestamp:
Feb 5, 2016, 11:13:54 AM (4 years ago)
Author:
cito
Message:

Support the uuid data type

This is often useful and also supported by SQLAlchemy

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/docs/contents/changelog.rst

    r817 r821  
    105105      strings.  You can restore the old behavior by deactivating the respective
    106106      typecast functions, e.g. set_typecast('date', None).
     107    - PyGreSQL now support the "uuid" data type, converting such columns
     108      automatically to and from Python uuid.UUID objects.
    107109    - PyGreSQL now supports the "hstore" data type, converting such columns
    108110      automatically to and from Python dictionaries.  If you want to insert
  • trunk/docs/contents/pg/adaptation.rst

    r818 r821  
    3737hstore                             dict
    3838json, jsonb                        list or dict
     39uuid                               uuid.UUID
    3940array                              list
    4041record                             tuple
  • trunk/docs/contents/pgdb/adaptation.rst

    r818 r821  
    3737hstore                             dict
    3838json, jsonb                        list or dict
     39uuid                               uuid.UUID
    3940array                              list
    4041record                             tuple
  • trunk/pg.py

    r820 r821  
    4343from re import compile as regex
    4444from json import loads as jsondecode, dumps as jsonencode
     45from uuid import UUID
    4546
    4647try:
     
    180181        'float': 'float4 float8',
    181182        'int': 'cid int2 int4 int8 oid xid',
    182         'hstore': 'hstore', 'json': 'json jsonb',
    183         'num': 'numeric',
    184         'money': 'money',
     183        'hstore': 'hstore', 'json': 'json jsonb', 'uuid': 'uuid',
     184        'num': 'numeric', 'money': 'money',
    185185        'text': 'bpchar char name text varchar'}
    186186
     
    864864        'time': cast_time, 'timetz': cast_timetz,
    865865        'timestamp': cast_timestamp, 'timestamptz': cast_timestamptz,
    866         'int2vector': cast_int2vector,
     866        'int2vector': cast_int2vector, 'uuid': UUID,
    867867        'anyarray': cast_array, 'record': cast_record}
    868868
  • trunk/pgdb.py

    r819 r821  
    7171from time import localtime
    7272from decimal import Decimal
     73from uuid import UUID
    7374from math import isnan, isinf
    7475from collections import namedtuple
     
    394395        'time': cast_time, 'timetz': cast_timetz,
    395396        'timestamp': cast_timestamp, 'timestamptz': cast_timestamptz,
    396         'int2vector': cast_int2vector,
     397        'int2vector': cast_int2vector, 'uuid': UUID,
    397398        'anyarray': cast_array, 'record': cast_record}
    398399
     
    730731        if value is None:
    731732            return 'NULL'
    732         if isinstance(value, (datetime, date, time, timedelta, Hstore, Json)):
     733        if isinstance(value,
     734                (datetime, date, time, timedelta, Hstore, Json, UUID)):
    733735            value = str(value)
    734736        if isinstance(value, basestring):
  • trunk/tests/test_classic_dbwrapper.py

    r820 r821  
    2525from decimal import Decimal
    2626from datetime import date, time, datetime, timedelta
     27from uuid import UUID
    2728from time import strftime
    2829from operator import itemgetter
     
    37033704        self.assertEqual(r, d)
    37043705
     3706    def testUuid(self):
     3707        d = UUID('{12345678-1234-5678-1234-567812345678}')
     3708        q = 'select $1::uuid'
     3709        r = self.db.query(q, (d,)).getresult()[0][0]
     3710        self.assertIsInstance(r, UUID)
     3711        self.assertEqual(r, d)
     3712
    37053713    def testDbTypesInfo(self):
    37063714        dbtypes = self.db.dbtypes
  • trunk/tests/test_dbapi20.py

    r817 r821  
    3030
    3131from datetime import date, time, datetime, timedelta
     32from uuid import UUID
    3233
    3334try:
     
    615616            con.close()
    616617        self.assertIsInstance(result, dict)
     618        self.assertEqual(result, d)
     619
     620    def test_uuid(self):
     621        d = UUID('{12345678-1234-5678-1234-567812345678}')
     622        con = self._connect()
     623        try:
     624            cur = con.cursor()
     625            cur.execute("select %s::uuid", (d,))
     626            result = cur.fetchone()[0]
     627        finally:
     628            con.close()
     629        self.assertIsInstance(result, UUID)
    617630        self.assertEqual(result, d)
    618631
Note: See TracChangeset for help on using the changeset viewer.