python - Working with a sql script in a Flask application -
i have created structure of basic flask application , need guidance executing sql script. folder structure this:
-simpleblog (name of app)
flask (contains virtual environment, 3 folders) app static (css, js) templates (html) __init__.py config.py run.py
i have sql script definition of 1 table, , don't know place , how execute it. know sqlite3 part of python, must install else?
look @ tutorial flask website explains how use sqllite database , execute sql scripts along suggested folder structure. usually, can create schema.sql file , put in main app folder. in example, can put as:
app static (css, js) templates (html) __init__.py config.py run.py schema.sql # sql script
http://flask.pocoo.org/docs/tutorial/schema/#tutorial-schema
to create initial database, use this. need install sqllite3 first.
http://flask.pocoo.org/docs/tutorial/dbinit/#tutorial-dbinit
basically, lets create initial database running following command:
sqlite3 /tmp/flaskr.db < schema.sql
lets understand above command. have database creation scripts (create,drop etc.) in schema.sql. take input sqlite3 executable , create database @ /tmp/flaskr.db. note: might need run following command first generate blank flaskr.db file
touch /tmp/flaskr.db
Comments
Post a Comment