Skip to content

Instantly share code, notes, and snippets.

@sarathlal-old
Last active November 7, 2019 06:50
Show Gist options
  • Save sarathlal-old/a1bc504b25f618cda2688efa54c2217f to your computer and use it in GitHub Desktop.
Save sarathlal-old/a1bc504b25f618cda2688efa54c2217f to your computer and use it in GitHub Desktop.
HSTORE in flask app
In your model, import requred module
from sqlalchemy.dialects.postgresql import HSTORE
from sqlalchemy.ext.mutable import MutableDict
Then use Hstore in our model class
class Submission(db.Model):
id = db.Column(db.Integer, primary_key=True)
timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
form_data = db.Column(MutableDict.as_mutable(HSTORE))
## Create HSTORE extension in our database
sudo -u postgres psql
You will be logged in to postgres SQL CLI interface user as postgres
postgres=#
### Select databse
\c your_database
Result will be
You are now connected to database "flask" as user "postgres".
### Create HSTORTE extension in that database
CREATE EXTENSION hstore;
The result will be
CREATE EXTENSION
### Check the table
\d your_table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment