Django and SphinxQL - how to disable transactions? - django

I have to use a SphinxQL in Django, but SphinxQL seems doesn't support transaction. How to disable transactions for SphinxQL connection? Is it possible? I replaced Django MySQL backend with MySQLdb and it works, but I prefer using native Django components.

You could manage that via
set autocommit=0
insert
...
commit
set autocommit=1

Related

Using mysql and mongodb together for Django

Can I use both relational-database(eg : mysql) and non-relational database(eg : mongodb) together as bacekend dbs for a Django project? If possible then how?
I use Django version 1.11
Yes, kind of. MongoDB is not supported as a backend for Django's ORM, however, you can use through MongoDB Python.
What I would do, in this case, is use MySQL as your default database in your DATABASES setting. I would use MySQL for all of my Django ORM functions, and only use MongoDB where I need it. You can then connect to MongoDB for non-ORM connections via Python. See here for connecting to MongoDB via Python: https://api.mongodb.com/python/3.4.0/
There used to be a Mongo backend - again, without much ORM support - but last I saw, it hasn't been updated in several years: https://github.com/django-nonrel
Good luck!

django - how can I write data to an external Mongo database?

I have a Django app that is using PostgreSQL. Everything is fine. However, I have a situation in which it would be very convenient for my Django app to update the Mongo database of an entirely different app that is running a different server, etc. How can I do this?
I dont know what Django is or how you are talking to Postgress, but ultimately, it boils down to using one of the MongoDB supported language drivers in order to communicate with MongoDB. The programming languages supported are here: drivers
One option to consider is MongoEngine, an Object-Document Mapper (ODM) that implements a declarative API similar to Django. You can then use Django's support for multiple databases to route requests appropriately.
See:
Django Support in MongoEngine
Django documentation: Multiple databases

In Django, how do I make a model that queries my legacy SQL Server and Oracle databases and sends that to the view?

I have a lot of old vbscript webpages using Classis ASP. Those ASP pages have lots of different databases queries to different databases all inside a given .asp file. I want to write those in Python and use Django as the framework. Will I be able to do this? I'm not sure how to start after I install Django. Sure, I can make a demo work, but that's not what I'm after. I will use the normal database "things" in MySQL or PostgreSQL, but sooner or later I have to hit those other databases and bring them back into Django, using Django's templating and so on.
Will I be able to do this? How do I make a model that queries my legacy SQL Server and Oracle database and send that to the view? Am I "fighting the framework" to accomplish this?
Just to be clear. I am not interested in messing with the stock database that Django uses for it's settings. That can stay as it is. I want to use that part for plugins, security (ldap), etc.
Thanks.
You can query different databases in your ORM calls by leveraging the using statement: https://docs.djangoproject.com/en/1.5/ref/models/querysets/#using
This would allow you to set up as many database definitions as you need in settings.py, then specify which DB to query at the view level. That way, you wouldn't have to change your model definition should you decide to consolidate your databases, etc.
Have you reviewed the Django multiple databases documentation?
Django has a built-in Oracle back end, so that should be fairly straightforward.
SQL Server can work through django-pyodbc but I found it fairly painful to set up. If you already have a generally working ODBC connection to your legacy SQL Server database connection from your Django environment it's no big deal, but it took me some trouble to get things set up to where I could use tsql to connect to my SQL Server database.
I also had some trouble with Unicode data from the SQL Server database until I forced it to use the appropriate (later) version of TDS. I just needed it for a script or two, so I set the 'TDSVER' environment variable and left it at that, but in theory there are other places you can set that.

Adding and Querying to MongoDB from Django

I am trying to build a DB system using Django as the framework and MongoDB for my database management system. How can I add things to a specific collection? Where should I specify the name of the collection?
Then, after I have added to the collection, how can I use a Django shell to ask for that information from Mongo?
You don't "add a collection" on MongoDB -- you just use them. In Django - MongoDB: (could not connect to localhost:27017) Connection refused you already got Django MongoDB Engine running, so I don't understand your question? You can use the Django ORM to get data into and out of MongoDB now.
There are many good tutorials of using mongodb with Django. One popular way is to use django-mongodb which integrates to django models. Here is their tutorial.
Another screencast: Integrating mongoDB and Django.

How to use multiple databases in a django application

I need to connect to multiple databases in my django application. I want to make connections to all the databases when ever I start the application and use those connections for all the requests. But I did not understand how to do that (setting these databases connections in global environment).
I tried to set database connections in settings.py and i tried to access those connections in my views using from django.conf import settings, But it is creating new database connections when ever new request comes.
Because of this my website always gives too many database connections error.
Can you please help me how to set these mysql connections in global environment?
Not only is this a planned feature, but one of this years GSOC projects is for multi database support. Alex Gaynor is working on it with Russell Keith-Magee as mentor. So I'm sure the result will be good.
The description of the project:
Django current has the low level hooks necessary for multiple database support,
but it doesn't have the high level API for using, nor any support
infrastructure, documentation, or tests. The purpose of this project would be
to implement the high level API necessary for the use of multiple databases in
Django, along with requisit documentation and tests.
The Django ORM does not support multiple databases.
There are some patches to modify Django with multiple database support called django-multidb You may have some luck with these, although they are a rather old.
Multiple DB support for Django is a planned feature.