Hi, I've been looking for a way to use PostgreSQL's hstore type in SA, and from all the options that I have found on the net the one written by Kyle Schaffrick (big thanks to him) and posted in this list[0] was the most promising.
[0] https://groups.google.com/forum/?fromgroups#!topic/sqlalchemy/IgdaTHHgQi0%5B1-25%5D So I took it and added some missing bits. The result can be found at <https://bitbucket.org/audriusk/hstore>. Apart from a couple of issues (and lacking proper tests), I feel that it's quite usable now. Here's the more detailed list of what's been changed: - As was suggested by Mike Bayer in the aforementioned thread, switched from MutableType to sqlalchemy.ext.mutable. - Removed usage of string_encode. In my tests it wasn't working as expected, Postgres was storing literals like '\x42' as 'x42'. As a result, now unicode strings are accepted as well. - Added NULL support for values and got rid of unquoted keys and values part in parser regexp (only NULL value is unquoted). - Fixed regexp to work with values which contain escaped quotes. - Changed pair() to return 'hstore(key, value)' instead of 'key => value' (according to PostgreSQL docs, the latter is deprecated). - HStoreColumn doesn't require HStore type as an argument anymore. - Used comparator, without it hstore specific methods were inaccessible from mapped classes. Also added HStoreColumnProp (borrowed the idea from GeoAlchemy). - Moved hstore operators and functions into HStoreMethods mixin class which is used by HStoreElement and HStoreComparator. The aforementioned issue is that __getitem__ and contains() do not work from comparator, the first one probably due to different way it's being accessed, the latter is shadowed by the method from some other class. Would be great to make at least contains() to work, if anybody has any ideas, please tell. This is the first time I dived deeper into SA, so the resulting code may use stuff improperly. Comments, suggestions, fixes are welcome! And Kyle, if you're reading this, it would be really nice if you noted under which license your initial code was published. -- Audrius Kažukauskas http://neutrino.lt/
pgpaoD2hKLX2K.pgp
Description: PGP signature