[Django] #35094: Add pure Python `dbshell` fallback

3 views
Skip to first unread message

Django

unread,
Jan 8, 2024, 7:11:56 AM1/8/24
to django-...@googlegroups.com
#35094: Add pure Python `dbshell` fallback
-------------------------------------+-------------------------------------
Reporter: Jake | Owner: nobody
Howard |
Type: New | Status: new
feature |
Component: Database | Version: 5.0
layer (models, ORM) | Keywords: sqlite dbshell in-
Severity: Normal | memory
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
`dbshell` attempts to shell out to the client tooling for the relevant
database engine (`sqlite3`, `psql` etc) for `dbshell`. If the tooling
isn't installed, it can't shell. However, for a more naive shell
implementation, it would be simple to pipe commands through to
`connection.cursor().execute` and get at least some of the benefit without
needing to install the client command-line tooling.

Whilst this wouldn't have the client-side magic (eg backslash commands in
Postgres or `.` commands in sqlite), nor tab complete, it can still be a
lot more useful than nothing. An implementation of this shipped in Python
3.12 for SQLite
(https://github.com/python/cpython/blob/main/Lib/sqlite3/__main__.py),
which can easily be adapted and made generic for all database engines.

Doing this has a side benefit of also giving support for a `dbshell` for
in-memory SQLite connections, which are currently misleading through
`dbshell`, as it doesn't reuse the same connection that Django does,
meaning any database bootstrapping done during startup (best-practice
aside) is lost. An in-process connection reuses the same connnection, and
thus allows access to that in-memory database.

--
Ticket URL: <https://code.djangoproject.com/ticket/35094>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Reply all
Reply to author
Forward
0 new messages