如何使用带有flask-sqlalchemy的Postgres'Hstore列?

chr*_*kso 4 python sqlalchemy flask flask-sqlalchemy hstore

我正在尝试实现此代码https://gist.github.com/1859653,它允许sqlalchemy与hstore列进行交互.

它在gist的评论中提到需要运行psycopg2.extras.register_hstore.什么时候应该运行这个功能?如果我做:

@app.before_request
def reg_hstore() :
register_hstore(db.engine.raw_connection(), True)
Run Code Online (Sandbox Code Playgroud)

heroku错误与'太多连接'

还提到使用pghstore(http://pypi.python.org/pypi/pghstore)而不是psycopg2,但它没有说明如何设置它.

另外,我想知道这个附加代码是否支持使用hstore索引.

pla*_*aes 6

从SQLAlchemy 0.8开始,psycopg2PostgreSQL的连接器(默认情况下)默认注册hstore扩展,并且apply_driver_hacks不再需要解决方法.

此外,SQLAlchemy 0.8+具有内置HSTORE类型支持.