Created
September 9, 2019 11:20
-
-
Save santiagosilas/cb1b9679ab2cf92288770bc9e8a94367 to your computer and use it in GitHub Desktop.
Running MySQL on VM Digital Ocean
This file contains hidden or 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
| # pip install flask | |
| # pip instal flask-sqlalchemy | |
| # sudo apt-get install libpq-dev | |
| # sudo pip install psycopg2 | |
| # sudo pip install redshift-sqlalchemy | |
| # sudo pip install sqlparse | |
| # sudo pip install mysqlclient | |
| #+----------+--------------+------+-----+---------+----------------+ | |
| #| Field | Type | Null | Key | Default | Extra | | |
| #+----------+--------------+------+-----+---------+----------------+ | |
| #| id | int(11) | NO | PRI | NULL | auto_increment | | |
| #| username | varchar(80) | YES | UNI | NULL | | | |
| #| email | varchar(120) | YES | UNI | NULL | | | |
| #+----------+--------------+------+-----+---------+----------------+ | |
| #3 rows in set (0.00 sec) | |
| from flask import Flask | |
| from flask_sqlalchemy import SQLAlchemy | |
| app = Flask(__name__) | |
| app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://test001:test001@localhost/dbdados' | |
| app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True | |
| db = SQLAlchemy(app) | |
| class User(db.Model): | |
| id = db.Column(db.Integer, primary_key=True) | |
| username = db.Column(db.String(80), unique=True) | |
| email = db.Column(db.String(120), unique=True) | |
| def __init__(self, username, email): | |
| self.username = username | |
| self.email = email | |
| def __repr__(self): | |
| return '<User %r>' % self.username | |
| if __name__ == '__main__': | |
| users = User.query.all() | |
| for u in users: | |
| print(u) | |
| #db.drop_all() | |
| #db.create_all() | |
| print('done.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment