summaryrefslogtreecommitdiff
path: root/django/db/backends/base/client.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/backends/base/client.py')
-rw-r--r--django/db/backends/base/client.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/django/db/backends/base/client.py b/django/db/backends/base/client.py
index 32901764aa..339f1e863c 100644
--- a/django/db/backends/base/client.py
+++ b/django/db/backends/base/client.py
@@ -1,3 +1,7 @@
+import os
+import subprocess
+
+
class BaseDatabaseClient:
"""Encapsulate backend-specific methods for opening a client shell."""
# This should be a string representing the name of the executable
@@ -8,5 +12,15 @@ class BaseDatabaseClient:
# connection is an instance of BaseDatabaseWrapper.
self.connection = connection
+ @classmethod
+ def settings_to_cmd_args_env(cls, settings_dict, parameters):
+ raise NotImplementedError(
+ 'subclasses of BaseDatabaseClient must provide a '
+ 'settings_to_cmd_args_env() method or override a runshell().'
+ )
+
def runshell(self, parameters):
- raise NotImplementedError('subclasses of BaseDatabaseClient must provide a runshell() method')
+ args, env = self.settings_to_cmd_args_env(self.connection.settings_dict, parameters)
+ if env:
+ env = {**os.environ, **env}
+ subprocess.run(args, env=env, check=True)