I'm looking into using PostgreSQL's hstore type in a SQLAlchemy
project, and before I possibly reinvent the wheel I was wondering if
anyone has/knows of an implementation of an hstore custom type for SQLA?
I'm basically just interested in simply mapping a stand-alone attribute
containing a python dict onto an hstore column, I don't require
auto-magic storage of extra attributes directly added to the object
a la examples/vertical.
Mainly I want the hstore segregated into it's own attribute because I'd
like to be able to expose expression language support for hstore's
operators (?, ->, ||, and so forth) to manipulate them server-side.
Any pointers?
Thanks,
-Kyle
start with 0.6, as we've expanded the capability for types to directly
affect how various operators are rendered, as well as to drive the return
type of expressions, which in turn allows that expression to have a say in
its own usage in another expression, as well as affects result row
behavior.
if hstore represents a python value that is "mutable" (which a dict would
be), mixing in MutableType will cause the ORM to maintain a copy of the
original version of the attribute in order to check for changes.
>
> Thanks,
> -Kyle
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To post to this group, send email to sqlal...@googlegroups.com.
> To unsubscribe from this group, send email to
> sqlalchemy+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sqlalchemy?hl=en.
>
>
> Kyle Schaffrick wrote:
> > Greetings,
> >
> > I'm looking into using PostgreSQL's hstore type in a SQLAlchemy
> > project, and before I possibly reinvent the wheel I was wondering if
> > anyone has/knows of an implementation of an hstore custom type for
> > SQLA?
> >
> > I'm basically just interested in simply mapping a stand-alone
> > attribute containing a python dict onto an hstore column, I don't
> > require auto-magic storage of extra attributes directly added to
> > the object a la examples/vertical.
> >
> > Mainly I want the hstore segregated into it's own attribute because
> > I'd like to be able to expose expression language support for
> > hstore's operators (?, ->, ||, and so forth) to manipulate them
> > server-side.
> >
> > Any pointers?
>
> start with 0.6, as we've expanded the capability for types to directly
> affect how various operators are rendered, as well as to drive the
> return type of expressions, which in turn allows that expression to
> have a say in its own usage in another expression, as well as affects
> result row behavior.
>
I had planned on using 0.6 just to get the benefit of the new
dialect+dbapi system.
I did see the @compiles() idiom in some example code, is this what
you're referring to? It looks like a great new feature.
Have there been any thoughts on user-extensible reflection? Some way
to say "when you reflect a DB column of type foo, use this custom type
class"? If I got the right impression from skimming, dispatching
reflected types is essentially a big cascade of if-statements at the
moment. I don't really know how many DBMS's in SA's arsenal have
extensible type systems, so not sure if it's worth the trouble. I
assume you can just override column information piecemeal without
having to give up reflection of columns with vanilla types.
> if hstore represents a python value that is "mutable" (which a dict
> would be), mixing in MutableType will cause the ORM to maintain a
> copy of the original version of the attribute in order to check for
> changes.
>
Good information, thanks. I can see why this would need to be handled
specially.
-Kyle
--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/U6JuhiAOJQMJ.
To post to this group, send email to sqlal...@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
<hstore.py>
--
On Sun, 2012-04-15 at 05:32 -0700, Kyle Schaffrick wrote:
> Wow, a blast from the past! :)
Yes.
> Which version of SQLAlchemy does your new version work with? It's
> great that you are now able to get rid of the HStoreComparator, that
> really makes it easier to use. The version of SQLA I was using 2 years
> ago when I wrote it required the custom comparator to make the
> operators work on the ORM InstrumentedAttribute as well as on the Core
> Column. I suppose the new version doesn't require this duplication?
I've gone back through the thread and I can't find a link to your work
[regarding the hstore implementation]. Can you post one?