How do i create unittest in pyramid with mongodb? - python

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.

Related

How to connect to existing SQLite DB using tortoise ORM?

I have existing SQLite DB with large data in it. I want to query the data asynchronously using tortoise ORM. How do I connect the database and query the data?
There is not magical tool. The inspectdb option in Aerich works for mysql.
You can create your models and read data from old sqlite db by driver and insert into new database.
The bulk_create method can improve the process time.

Using Apache Ignite with Django

We have an existing Apache Ignite in-memory DB with lots of stored data. I want to connect my existing Django web application to the Ignite DB in order to query the existing data. Are there any examples of how to connect a Django application to an Apache Ignite DB and how to query the DB using the Django ORM?
You can use JDBC drivers with Django ORM: How to write custom database adapter for django using JDBC drivers?
Then, you can use Ignite JDBC driver: https://ignite.apache.org/docs/latest/SQL/JDBC/jdbc-driver
Django ORM requires a special adapter for each kind of database server. Such an adapter is called “database backend” in Django terminology. There is no Django database backend for Ignite. There is also no universal, middle-ground backend I know of, that can be used with Ignite.
You can implement your own custom backend (guidelines) or try to pick up the latest attempt in creating a more-or-less server-independent ODBC backend. But in your place I'd probably not get involved in any of this, since it implies a lot of work not directly related to your task.
I'd just convert the data with one-off script (or Django management command), using pyodbc or pyignite as a source and Django model as a target.

Use Django with MongoDB

I have a large mongo database with documents and i want to make Django website that is going to be a client to this mongo database but it can only filter (aggregate) and view information from database without any edit/update operations. I don't want to put other web site data (users' data, comments, other information) to mongo db.
I'm new to django framework and i wonder if it is better to connect mongodb and django using, for example, mongoengine and use two databases (one for the web site data, and the second one for external documents in mongodb) or use pymongo inside django to fetch data from external db and somehow transform it to djungo models?
Yup, you're spot on, in your case of needing two separate databases, it would be better to use mongoengine in order to use two separate databases. Check out this link. It goes over defining what database to use on a per-model basis so to say.
That most likely would work great. Basically you can query using the model the same way, regardless of the database is uses, but describe which database to use on the model itself.
Hope this helps!

Query a database in Django and not creating a db

Am I able to query a database I have in place with Django and not creating a database? I ask this question because all documentation I have read shows Django as creating a database. I do not want to create a DB, but use a DB I have in place in my Django apps. I have read through the Django docs, Google searches, and YouTube but I am unable to find anything further on not creating a DB and only using a DB I have in place.

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