Where does the data go?
September 21, 2019 10:04 AM   Subscribe

I am learning to use Flask as you recommended and it's going great but I don't understand something. When I make a database instance and my Flask app sends data to it, where IS that data? My Flask app has a variety of files with file extensions unfamiliar to me, but I do not see the data that must be in one of them in any human-readable form. Please explain like I'm five. Seriously, like I'm five, please.
posted by pH Indicating Socks to Computers & Internet (6 answers total) 5 users marked this as a favorite
 
Databases will usually store data in some super fancy human-illegible format so they can use all sorts of clever tricks to be able to operate on the data really really efficiently and quickly. This is one of the big advantages (among many others) of using specialized database software as opposed to just storing it in some sort of plain text format.
posted by Television Name at 10:37 AM on September 21, 2019


Best answer: It's stored in a database. Flask can work with many databases, but as a python app, if you have not installed any other database, the default choice is sqlite3. Look for a file with (possibly) an .sq3 suffix.

You can interact with this file using sqlite, which you can install, and can run as a text-based command-line program. If you just want to browse/view this file, you may be better off with something like this: https://sqlitebrowser.org/dl/
posted by Maxwell_Smart at 10:45 AM on September 21, 2019 [5 favorites]


Flask on its own doesn’t use a database, so you’ve presumably added something like Flask-SQLAlchemy? In which case you probably had to tell it what database to use. In a Flask-SQLAlchemy’s case you’d set the SQLALCHEMY_DATABASE_URI variable, which would point at a Postgres or MySQL database or at a path that starts “sqlite:///“. That path would be to a file on your computer that contains the database.

Sorry, that’s probably a bit much for “like I’m five” but it’s hard to be more precise without knowing what you’ve set up so far. This is the database section of a great Flask tutorial series.
posted by fabius at 11:15 AM on September 21, 2019 [1 favorite]


A database is a service. It puts information in a place on the disk. Where on the disk? Doesn’t matter. Don’t go looking for it, because you wouldn’t understand it anyway. Just know that you can tell the database what information you want to store and retrieve. (The way you tell it is n a specialized language called SQL. You should probably learn some SQL someday, but you might never have to actually use it. )

Flask is also a service. It takes in requests from the client on a distant computer, and it processes those into responses to send back. Part of that process involves going over to the database and negotiating with the database so you don’t have to. Flask speaks SQL, for instance.

In other words, don’t try to figure out how Flask talks to the database unless you’re really curious. Just know that flask will handle saving information and getting it back. It’s a bit like when you’re playing a game on a console and it offers to save your game for you. Only the terminally curious would go looking in the file structure of the console to find where the save game was, and they would know that they would never figure out the format of it anyway. You just left the game save it for you.

I know some people will say that it’s important to learn how to deal with the database directly. Long-term, yes it is. Short term, let Flask handle it for you.
posted by argybarg at 12:30 PM on September 21, 2019


Response by poster: I installed DB Browser for Sqlite as Maxwell_Smart suggested, opened a .sqlite file in it and Hey! There's my data! Yay!

So the answer is, should any of my fellow five-year-olds read this... the data is stored in a database file and if you were doing the Flaskr tutorial, for example, that database file is flasker-tutorial\instance\flasker.sqlite, which is not human-readable except in DB Browser.
posted by pH Indicating Socks at 12:46 PM on September 21, 2019 [1 favorite]


Best answer: Well done!

In case it helps understand, if using that Flaskr tutorial. the location of the database file is set in the file flaskr/__init__.py (look for the line that starts with DATABASE), shown on this page.

The location of the file is also mentioned at the bottom of this other page about initialising the database.
posted by fabius at 1:01 PM on September 21, 2019 [1 favorite]


« Older Help me match some burlged curtains and rods!   |   Make them worship me as a coffee pod god Newer »
This thread is closed to new comments.