Use sqlite3 for prototyping in a flask app - python

I am creating the prototype for a webapp using flask,
flask-sqlalchemy and some toy sqlite3 database.
I am using sqlite3 databases just for development purposes, but ideally
I would like to use some different SQL database in production.
What I am finding hard to understand is how to use SQLalchemy and sqlite3 in a way that I won't have to rewrite my queries once I use the production database.
A silly example: in mysql I can get a list of all the databases available (whose names I use to populate a "drop menu") using "SHOW DATABASES ", but in sqlite I have to do this by listing all the files in a directory.
What is the best way to prototype a webapp using sqlite3, without having to rewrite all the queries after?

Related

Easiest way to connect to SQL Server on Flask app for search query?

I'm looking to give my Flask app data to query, since the end app will be like a search engine + calculator.
I'm not sure what the easiest way to connect SQL Server data to the Flask app is, and how to query based on certain fields.
I've looked into Elasticsearch and it's a little too advanced for me at the moment, and wasn't sure if there was an easier way.
I've also used PYODBC in the past to build Pandas dataframes based on query results, but I was selecting * from the given table. For this, I want to use the user input and then query the database based on that input and return the result.
Perhaps, you should have a look at SQLAlchemy. Some info on how to use it with MS SQL Server may be found here.

Using Flask and Flask-SQLAlchemy, how could I change the database connection in a route?

Business case:
We have multiple databases that need to be accessed and we don't know which until a URL/Route is called. The database server and database name are part of the route.
example: http://<flask_server>/<db_server>/<db_name>/weeklyreport
Since standard Flask-SQLAlchemy uses APP settings to define the DB connection and APP settings cannot (should not) be changed at runtime... how could one accomplish this?
I've just sidestepped the issue by using straight SQLAlchemy and not Flask-SQLAlchemy as I could find no way around this. For my needs I won't miss the benefits of the Flask wrappers.

Flask with two databases (mysql and mongo)

Is it possible in Python Flask to connect to 2 databases, one mysql and one mongo?
This is for an e-commerce app where the users are stored in mysql and the products in mongo.
If yes, can you give me an example?
Thanks.

Use two databases in Django 1.5

I have a Django 1.5 application with a SQLite or MySQL database. At the local server I have an Oracle database which I typically connect to with a connection string
"TNS=TNS-name; UID=user; PWD=pwd;".
How is it possible to print data from the local Oracle database in my Django application? Actually, I want to transfer data from the Oracle database into my main SQLite/MySQL database. I've seen some tutorials how to use an Oracle database as main database source in a Django application, but I want to keep my main database source and just load some specific data from the Oracle database in a specific Django view.
Thank you.
I'm not quite sure if this is what you're looking for, but the Django Docs seem to do a good job explaining it (if I interpreted it correctly). In short, you need to add it to your list of databases in your settings file and create a router. The lookup chain for databases is detailed here.

How do i create unittest in pyramid with mongodb?

I have a pyramid project that uses mongodb for storage. Now I'm trying to write a test but how do I specify connection to the mongodb?
More specifically, which database should I connect to (test?) and how do I use fixtures? In Django it creates a temporary database but how does it work in pyramid?
Just create a database in your TestCase.setUp and delete in TestCase.tearDown
You need mongodb running because there is no mongolite3 like sqlite3 for sql
I doubt that django is able to create a temporary file to store a mongodb database. It probably just use sqlite:/// which create a database with a memory storage.

Categories

Resources