feat(\db-tool\): introduce unified db-tool package with postgres harness and tests (T0-T8)

This commit is contained in:
2026-04-30 09:06:44 +00:00
parent 395bddee94
commit b5dcbf08a1
27 changed files with 2417 additions and 1 deletions

View File

@@ -0,0 +1,41 @@
: "${OLD_NAMESPACE:=}"
nl=$(printf '\nx')
nl=${nl%x}
___pop_namespace() {
v=${OLD_NAMESPACE%%"$nl"*}
case $OLD_NAMESPACE in
*"$nl"*)
OLD_NAMESPACE=${OLD_NAMESPACE#*"$nl"}
;;
*)
OLD_NAMESPACE=
;;
esac
printf '%s\n' "$v"
}
___peek_namespace() {
printf '%s\n' "${OLD_NAMESPACE%%"$nl"*}"
}
___push_namespace() {
if [ -n "$OLD_NAMESPACE" ]; then
OLD_NAMESPACE=$1"$nl$OLD_NAMESPACE"
else
OLD_NAMESPACE=$1
fi
}
change_namespace() {
___push_namespace "$HECTIC_NAMESPACE"
export HECTIC_NAMESPACE="$1"
}
restore_namespace() {
HECTIC_NAMESPACE=$(___pop_namespace)
export HECTIC_NAMESPACE
}

View File

@@ -12,4 +12,13 @@ in {
colors = hectic.writeDash "colors.sh" ''
${builtins.readFile ./colors.sh}
'';
change_namespace = hectic.writeDash "change_namespace.sh" ''
${builtins.readFile ./change_namespace.sh}
'';
quote = hectic.writeDash "quote.sh" ''
${builtins.readFile ./quote.sh}
'';
pager_or_cat = hectic.writeDash "pager_or_cat.sh" ''
${builtins.readFile ./pager_or_cat.sh}
'';
}

View File

@@ -0,0 +1,8 @@
pager_or_cat_init() {
# Pipe to pager only if stdout is a terminal, otherwise output directly
if [ -t 1 ]; then
PAGER_OR_CAT="${PAGER:-less}"
else
PAGER_OR_CAT=cat
fi
}

View File

@@ -0,0 +1 @@
quote() { printf "'%s'" "$(printf %s "$1" | sed "s/'/'\\\\''/g")"; }