The extension provides facilites for implementing Django-like ./manage.py dbshell
command
Install the extension with one of the following commands:
$ easy_install flask-dbshell
or alternatively if you have pip installed:
$ pip install flask-dbshell
Example of a simple script that runs mysql's shell
from flask.ext.dbshell import DbShell
def main():
dbshell = DbShell('mysql://scott:tiger@server/dbname')
dbshell.run_shell()
if __name__ == '__main__':
main()
Example of use with Flask-Script:
from flask import Flask
from flask.ext.script import Manager
from flask.ext.dbshell import DbShell
class DevConfig(object):
DATABASE_URI = 'sqlite:///demo.sqlite'
app = Flask(__name__)
app.config.from_object(DevConfig)
manager = Manager(app)
@manager.command
def dbshell():
shell = DbShell(url=app.config['DATABASE_URI'])
shell.run_shell()
if __name__ == "__main__":
manager.run()
Tested with 2.6.x and 2.7.x