On Wed, Feb 25, 2009 at 13:40, Gregg Lind <gregg.l...@gmail.com> wrote: > > Thank you, that's simpler than my attempts, for sure!
You're welcome. Note that this implementation is very simple. Depending of your use case, you probably should take a look at MutableType [1] and types.TypeEngine.is_mutable(). [1] - http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/types.html#sqlalchemy.types.MutableType > > > > On Wed, Feb 25, 2009 at 10:27 AM, Roger Demetrescu > <roger.demetre...@gmail.com> wrote: >> >> On Wed, Feb 25, 2009 at 11:39, Gregg Lind <gregg.l...@gmail.com> wrote: >>> >>> How does one create a TypeDecorator to export and import JSON to a >>> database using SA? >> >> I did something like that recently: >> >> >> ----------------- >> >> from sqlalchemy import types >> import simplejson >> >> >> class JsonString(types.TypeDecorator): >> impl = types.String >> def process_result_value(self, value, dialect): >> if value is None: >> return None >> else: >> return simplejson.loads(value) >> >> def process_bind_param(self, value, dialect): >> if value is None: >> return None >> else: >> return simplejson.dumps(value) >> >> ----------------- >> >> >> []s >> Roger >> >> > >> > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---