Skip to content

Instantly share code, notes, and snippets.

@theY4Kman
Created May 6, 2015 20:40
Show Gist options
  • Select an option

  • Save theY4Kman/6d47802f6164339b27cf to your computer and use it in GitHub Desktop.

Select an option

Save theY4Kman/6d47802f6164339b27cf to your computer and use it in GitHub Desktop.
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_BINDS'] = {
'postgres': 'postgresql+psycopg2://wazinit:wazinit@localhost/test_binds',
'mysql': 'mysql://hivelocity:test@localhost/hivelocity_shared',
}
db = SQLAlchemy(app)
class PostgresModel(db.Model):
__tablename__ = 'postgres_model'
__bind_key__ = 'postgres'
id = db.Column(db.Integer, primary_key=True)
class MySQLModel(db.Model):
__tablename__ = 'mysql_model'
__bind_key__ = 'mysql'
id = db.Column(db.Integer, primary_key=True)
my_enum = db.Column(db.Enum('A', 'B'))
if __name__ == '__main__':
db.create_all()
Flask-SQLAlchemy
psycopg2
MySQL-python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment