I get some issues when appending a model to an "orm.relationship" 
(UnorderableType error).  Which is annoying but can be worked around.

I also use SQLAlchemy-Continuum which seems to have issues with retrieving 
"orm.relationship"s.  It will attempt to query using the shortuuid type 
without transforming it to the uuid type.  Obviously this is third-party 
stuff but I am curious how I could go about creating my own relationship 
mapper.  Something that would be resilient enough to understand shortuuids 
need to be converted to UUIDs.

I thought there might be something obviously wrong with my implementation 
(since its my first one) which I why I lead off with that.

On Friday, May 19, 2017 at 6:19:45 AM UTC-7, Mike Bayer wrote:
>
> looks fine to me?   what did you have in mind? 
>
>
>
> On 05/18/2017 11:29 PM, Colton Allen wrote: 
> > I want to make my UUID's prettier so I've gone about implementing a 
> > ShortUUID column based on the shortuuid library[1].  The idea is to 
> > store the primary key as a UUID type in postgres (since its optimized 
> > for that) and transform the UUID to a shortuuid for presentation and 
> > querying.  This is my first attempt at implementing it.  It has some 
> > short comings. 
> > 
> > I was wondering if you had any advice for fully baking the 
> > implementation.  I've pasted the code I have so far. 
> > 
> > 
> > from sqlalchemy_utils.types.uuid import UUIDType 
> > 
> > import uuid 
> > import shortuuid 
> > 
> > 
> > def _decode_shortuuid(value): 
> >      try: 
> >          return shortuuid.decode(value) 
> >      except ValueError: 
> >          return None 
> > 
> > 
> > def _encode_shortuuid(value): 
> >      try: 
> >          if value is None: 
> >              return None 
> >          return shortuuid.encode(value) 
> >      except KeyError: 
> >          return None 
> > 
> > 
> > class ShortUUID(UUIDType): 
> >      """Converts UUIDs to ShortUUIDs for readability's sake.""" 
> > 
> >      def process_bind_param(self, value, dialect): 
> >          """Process a ShortUUID to a UUID.""" 
> >          if value is None: 
> >              return value 
> > 
> >          if type(value) != uuid.UUID: 
> >              value = _decode_shortuuid(value) 
> >          return super().process_bind_param(value, dialect) 
> > 
> >      def process_result_value(self, value, dialect): 
> >          """Return a ShortUUID encoded UUID.""" 
> >          value = super().process_result_value(value, dialect) 
> >          return _encode_shortuuid(value) 
> > 
> > 
> > 1. https://github.com/skorokithakis/shortuuid 
> > 
> > -- 
> > SQLAlchemy - 
> > The Python SQL Toolkit and Object Relational Mapper 
> > 
> > http://www.sqlalchemy.org/ 
> > 
> > To post example code, please provide an MCVE: Minimal, Complete, and 
> > Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> > description. 
> > --- 
> > 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] <javascript:> 
> > <mailto:[email protected] <javascript:>>. 
> > To post to this group, send email to [email protected] 
> <javascript:> 
> > <mailto:[email protected] <javascript:>>. 
> > Visit this group at https://groups.google.com/group/sqlalchemy. 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to