Last active
November 7, 2019 06:50
-
-
Save sarathlal-old/a1bc504b25f618cda2688efa54c2217f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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