helpers2.1: mysql/psql: rename ynh_SQL_connect_as to ynh_SQL_execute for semantics and consistency with ynh_SQL_execute_as_root

This commit is contained in:
Alexandre Aubin 2024-06-10 17:00:21 +02:00
parent 05a02221b9
commit 4d5ae9d32c
2 changed files with 12 additions and 12 deletions

View file

@ -2,17 +2,17 @@
# Open a connection as a user # Open a connection as a user
# #
# usage: ynh_mysql_connect_as --user=user --password=password [--database=database] # usage: ynh_mysql_execute --user=user --password=password [--database=database]
# | arg: -u, --user= - the user name to connect as (by default, $db_user) # | arg: -u, --user= - the user name to connect as (by default, $db_user)
# | arg: -p, --password= - the user password (by default, $db_pwd) # | arg: -p, --password= - the user password (by default, $db_pwd)
# | arg: -d, --database= - the database to connect to (by default, $db_name) # | arg: -d, --database= - the database to connect to (by default, $db_name)
# #
# examples: # examples:
# ynh_mysql_connect_as --user="user" --password="pass" <<< "UPDATE ...;" # ynh_mysql_execute <<< "UPDATE ...;"
# ynh_mysql_connect_as --user="user" --password="pass" < /path/to/file.sql # ynh_mysql_execute < /path/to/file.sql
# #
# Requires YunoHost version 2.2.4 or higher. # Requires YunoHost version 2.2.4 or higher.
ynh_mysql_connect_as() { ynh_mysql_execute() {
# ============ Argument parsing ============= # ============ Argument parsing =============
local -A args_array=([u]=user= [p]=password= [d]=database=) local -A args_array=([u]=user= [p]=password= [d]=database=)
local user local user

View file

@ -5,17 +5,17 @@ PSQL_VERSION=13
# Open a connection as a user # Open a connection as a user
# #
# usage: ynh_psql_connect_as --user=user --password=password [--database=database] # usage: ynh_psql_execute --user=user --password=password [--database=database]
# | arg: -u, --user= - the user name to connect as (by default, $db_user) # | arg: -u, --user= - the user name to connect as (by default, $db_user)
# | arg: -p, --password= - the user password (by default, $db_pw) # | arg: -p, --password= - the user password (by default, $db_pw)
# | arg: -d, --database= - the database to connect to (by default, $db_name) # | arg: -d, --database= - the database to connect to (by default, $db_name)
# #
# examples: # examples:
# ynh_psql_connect_as 'user' 'pass' <<< "UPDATE ...;" # ynh_psql_execute <<< "UPDATE ...;"
# ynh_psql_connect_as 'user' 'pass' < /path/to/file.sql # ynh_psql_execute < /path/to/file.sql
# #
# Requires YunoHost version 3.5.0 or higher. # Requires YunoHost version 3.5.0 or higher.
ynh_psql_connect_as() { ynh_psql_execute() {
# ============ Argument parsing ============= # ============ Argument parsing =============
local -A args_array=([u]=user= [p]=password= [d]=database=) local -A args_array=([u]=user= [p]=password= [d]=database=)
local user local user
@ -50,8 +50,8 @@ ynh_psql_execute_as_root() {
database="--database=$database" database="--database=$database"
fi fi
ynh_psql_connect_as --user="postgres" --password="$(cat $PSQL_ROOT_PWD_FILE)" \ ynh_psql_execute --user="postgres" --password="$(cat $PSQL_ROOT_PWD_FILE)" \
$database <<<"$sql" --database="$database" <<<"$sql"
} }
# Execute a command from a file as root user # Execute a command from a file as root user
@ -74,8 +74,8 @@ ynh_psql_execute_file_as_root() {
database="--database=$database" database="--database=$database"
fi fi
ynh_psql_connect_as --user="postgres" --password="$(cat $PSQL_ROOT_PWD_FILE)" \ ynh_psql_execute --user="postgres" --password="$(cat $PSQL_ROOT_PWD_FILE)" \
$database <"$file" --database="$database" <"$file"
} }
# Create a database and grant optionnaly privilegies to a user # Create a database and grant optionnaly privilegies to a user