Skip to content
Sign upLog in
← Back to Community

databases

Profile icon
adl212

Hi, I'm not really sure how to connect an external database to my programs in python. It doesn't really matter what external database to use. And do databases like SQL work on repl.it?

Voters
Profile icon
EmonSaha
Profile icon
adl212
Comments
hotnewtop
Profile icon
[deleted]

SQLite is the right database to use as it is part of Python. This poll app will show how to use SQLite to store values. Note there is some setup code to run first. This creates the database and table and inserts some values. The code is commented so hopefully you will be able to work out what is happening: https://repl.it/@malvoliothegood/poll-using-sqlite3#main.py

Here is a link to a useful tutorial: https://www.tutorialspoint.com/sqlite/sqlite_python.htm

Profile icon
adl212

@malvoliothegood
Ok, thanks!

Profile icon
adl212

@malvoliothegood
Will repl.it update the databases so that it will update even when it is not used by the owner? I'm not really sure if it will because text files don't update and save when written to by, not the owner but users, by a program.

Profile icon
[deleted]

@adl212
That is a good question. I did test it out when I last worked on the repl, but can't remember the result! I need to look at it again.

Profile icon
adl212

@malvoliothegood
Ok, great!

Profile icon
[deleted]

@adl212
I have tested it out and the database only persists storage of values if you are logged in, and have the app running. In other words, if the app is opened by going to it's URL using a browser, values will not persist in the database.

Profile icon
adl212

@malvoliothegood
Ok. Unfortunately, that is why I think I need to use an external database so that all data will be saved. Do you know of any external databases that are easy to use in python repl it?

Profile icon
[deleted]

@adl212
Have a look at mongodb. Here are some links that may help:

Profile icon
adl212

@malvoliothegood
Will the data be saved when my program is used by users? Or will it be like the same with SQLite?

Profile icon
[deleted]

@adl212
Possibly not. How about using PythonAnywhere rather than repl.it? There is a free account that allows one web app. You can import the sqlite3, package, create: a database, tables, and read and write to it, etc.

Check out what features it has to offer: https://www.pythonanywhere.com/#id_hosting_details

Also check out this tutorial A beginner's guide to building a simple database-backed Flask website on PythonAnywhere: https://blog.pythonanywhere.com/121/

All the best. Let me know how you get on :))

Profile icon
adl212

@malvoliothegood
Ok, thanks for the great advice!

Profile icon
MocaCDeveloper

Yes. Actually, I think SQL is the most popular to be used on rep.it. Especially with Python, if that is the language you are wanting to use.
But yea, SQL works on repl and usually you would use Python as the language for working with database-type ideals :)
If I answered your question, please select my comment as the one that answered your question(I think it should be a check mark)

Profile icon
adl212

@targetfanttthat
Ok, that makes sense and I am using Python currently. I'm not going to choose as the correct answer because it doesn't really answer my question on how to use it.