Skip to content

Instantly share code, notes, and snippets.

@iromli
Last active August 29, 2015 14:07
Show Gist options
  • Save iromli/bbc7a07f4518952eb187 to your computer and use it in GitHub Desktop.
Save iromli/bbc7a07f4518952eb187 to your computer and use it in GitHub Desktop.
import flask
from flask.ext.sqlalchemy import SQLAlchemy
from sqlalchemy.ext.declarative import DeferredReflection
DEBUG = True
# Adjust your db connection
SQLALCHEMY_DATABASE_URI = "postgresql://user:passwd@localhost:5432/dbname"
app = flask.Flask(__name__)
app.config.from_object(__name__)
db = SQLAlchemy(app)
class User(DeferredReflection, db.Model):
__tablename__ = "users"
@app.route("/")
def index():
return flask.jsonify({
"data": [{
"username": user.username,
"email": user.email,
"fullname": user.fullname,
} for user in User.query.all()]
})
if __name__ == "__main__":
DeferredReflection.prepare(db.engine)
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment