sqlite3 - Where does my sqlite database go? -
This can be a dumb question, but how am I confused about how the real SQL is being used by the database My Flask application works with the database I have a python file, models.py which defines a SQLAlchemy database schema, and then I have this part of my code that creates a database for it
if __name__ == '__main__': to sqlalchemy.orm import from sessionmaker engine = create_engine QLAlchemy import from import_engine to datetime import timedelta ('SQLite: //', echo = true) Base.metadata.create_all (engine) session = sessionmaker (bind = engine) session = session () #A sample user user = add user (name = 'Phillip House', password = "exam") session.add (user) session.commit ()
I run that file and it works fine, but now I am confused about what happens with the database..how can I access it in any other application? I have also heard that it can only be in memory, and if this is the case then how do I create a permanent database file, from which I can use my application?
Also in my application, it
pwd = os.path.abspath (os.curdir) debug = true SQLALCHEMY_DATABASE_URI = 'SQLite :: /// {} / Arkaios How do I reference my SQLite database in the config file?
I do not know if it's any help.
Thank you!
With regard to SQLAlchemy with SQLite.
As you guessing, you are actually building a SQLite database in memory when you use sqlite: //
as your connection string If you were to use sqlite: /// {} /arkaios.db.format (PWD)
then you can create a new database in your current directory. If this is what you intend to do, you can access that database from other applications, then you should import your connection string from your configuration file and instead sqlite: //
.
Comments
Post a Comment