FreedomBox/plinth/db/mariadb.py
Sunil Mohan Adapa 61ff15a04f
*: Use action_utils.run instead of subprocess.run
- This is to capture stdout and stderr and transmit that from privileged daemon
back to the service to be displayed in HTML.

Tests:

- Unit tests and code checks pass.

- Some of the modified actions work as expected.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2025-09-29 16:58:53 +03:00

20 lines
559 B
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""Utilities to help with MariaDB/MySQL databases.
Uses utilities from 'mysql-client' package such as 'mysql' and 'mysqldump'.
"""
import subprocess
from .. import action_utils
def run_query(database_name: str, query: str) -> subprocess.CompletedProcess:
"""Run a database query using 'root' user.
Does not ensure that the database server is running.
"""
return action_utils.run(
['mysql', '--user=root', '--database', database_name],
input=query.encode('utf-8'), check=True)