epantry/django-sql-explorer — pull request #84 by abide-chris-e (2014-06-27 12:50:48+00:00)
Title: dumb attempt to find relevant connection

If you're using django database routers and multiple databases/connections then the choice of "always use default" or "always use EXPLORER_CONNECTION_NAME" is a bit restrictive.

This change does a Very Dumb Check to see if the table name for any known model appears in the SQL to be executed. It doesn't parse the SQL- it doesn't even split it into words, so it could find a table name in a constant or a column name or a partial match of some other table name, or anywhere. If it finds it then it uses the connection for database reads on that model.

I guess a new SETTING to enable/disable this behaviour would be good. Also some basic parsing to target real table names in queries .. does django have some built-in basic SQL parsing utilities? Perhaps there's a python library we could use?