-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Aug 11, 2012, at 3:18 PM, Audrius Kažukauskas wrote:

> 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!

very nice job understanding quite a number of SQLAlchemy APIs, this is good 
work.   It reminds me also of how we still have a weakness in the Core API, 
that we can't add new comparison methods at the Core level onto Column objects 
and such.   The column_property() here is a well-designed workaround for that.

Ideally MutationDict would be part of SQLAlchemy,  from the mutable extension.  
 the extension should have "mutable" versions of basic types list, dict, set.   
 That's a TODO and also we'd need lots of tests.

The contains()  method is addressed by allowing the "escape" argument through:

- --- a/hstore.py       Sat Aug 11 19:17:46 2012 +0300
+++ b/hstore.py Mon Aug 13 10:58:07 2012 -0400
@@ -188,7 +188,7 @@
         """
         return self.op('?')(other)
 
- -    def contains(self, other):
+    def contains(self, other, **kw):
         """Boolean expression.  Test if keys are a superset of the keys of
         the argument hstore expression.
         """


as for __getitem__ I don't want to expose that as a potential operator right 
now, I'd rather look into a deeper change to the operator system first so that 
hacks like _HStoreBinaryExpression aren't needed, then we can figure out if 
there's a space for __getitem__ types of things.










> 
> 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/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (Darwin)
Comment: GPGTools - http://gpgtools.org

iQEcBAEBAgAGBQJQKRZvAAoJEDMCOcHE2v7hxO0H/0PhmViuP2ndpPCvxmtLEgx4
PFuyl7avGwOh0+64HQl1YENFtNG8ZGDINU7EilsO5HsGVTYqlbT1YsX1ecQV1ury
vLCnf6EYWAczpYa2pTgpn2mNj4WzymoFNx7uMqsoysc6nZCp2BwhMxJTEkHV5BpC
ukTDWJ4iKXCAfISDY8QaR0Ani7IjcYHN5h2Ig8v4EH9DYrocE3E6Hd87kW4N9R+N
P9zJ5/xCZBlUIxpfUsb4R8Kicv+IC+S4WAcs6oIqAllwdFTiZ/PEbRNfXuhSP4CD
zyaSUVEPeGLQDTKky86GhmA3efTjC/CH2/MeAdqaQbMYmDU7gZZiQFulwftrSms=
=1pfk
-----END PGP SIGNATURE-----

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to