Flask with two databases (mysql and mongo) - python

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.

Related

SQLAlchemy Postgresql database django

I am new to Django and have a question in regards to whether or not I have to re-enter data or can use existing data from a postgres database and apologize if this has been asked before.
I have a Postgres database in which I created with SQLAlchemy ORM. I use this database for data analysis and want to create a web app for the data presentation. I know that Django has its own modeling system and ORM, do I have to recreate the database from scratch since I created this with SQLAlchemy's ORM?
You can use inspectdb command from Django.
https://docs.djangoproject.com/en/4.0/howto/legacy-databases/

Customize the Django ContentTypes and AdminLog and Migration model

I am working on a Django project and it requires 3 different database servers with different engines like MySql, PostgreSQL and SQLite.
SQLite has all the client side setting table, tables with not shared data [app has a feature to not upload some data to the server] and configuration tables and it is on the client machine through a tweaked C# app to create a django server environment and show the django site in a browser control like a native application.
PostgreSQL has tables that can be accessed by different clients on the network and has different tables with values of shared data. They maintain integrity with SQLite data through ContentType.
Django provides the contentType table that is created in both SQLite and PostgreSQL. Due to heavy use of other database managing tables we require them to be in a MySQL database on a separate server. So it would be great to have django_content_types, django_admin_log and django_migration in that MySQL server.
ContentTypes table is also used a lot and it is difficult to maintain contentTypes form two different database tables so we require it to be in one separate one with values form both the databases. And when one goes there why not the other two: django_migration, django_admin_log.
Also there is requirement to store raw SQL DDL queries in the database to track changes outside of the Django ORM and so it makes sense to add rows to django_migration and a new column to store raw SQL queries.
Also, this is the last thing for sure, django_admin_log only logs admin-site changes and also lacks data in message columns when new row is added or deleted. We really require it to store the JSON of values added to the particular table when adding and when deleting, the instance [json format of row] to message column about the record deleted. And require it to log all transactions on instances of both the databases.
I am looking to [customize/extend/create my own and override] these models in a Django App to gain the above expected behavior and have a portable app to use it in future such projects.
Regards,
    Aagam Sheth

Google app engine - multiple services - one database. Flask - sqlalchemy

I want to have multiple services on Google App Engine powered with Flask and Flask-SQLAlchemy and one MySQL database. The problem is that I have database version control (Flask-Migrate) and ORM definition (models.py) in one app.
The question is, how can I have right access to the database with the ORM from another service (another flask app)? Should I define the same models.py file for all this apps (share one copy)? I don't think this is the best solution
Thanks!

Use sqlite3 for prototyping in a flask app

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?

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.

Categories

Resources