*_store,*_file_store: Map is used for %TABLE% etc. substituting. Uplift

This commit is contained in:
Sebastian Gniazdowski 2018-05-19 07:42:52 +02:00
parent ab90055ec4
commit 07f17e0399
3 changed files with 21 additions and 12 deletions

View file

@ -3,22 +3,20 @@
# $1 - target database ($sel_db)
# $2 - target table ($sel_table)
# $3 - name of array that holds entries
# $4 - target table with %ID and %CN resolved
setopt localtraps
[[ "$ZFLAI_LIBS_SOURCED" != "1" ]] && source "${ZFLAI_SRC_DIR}/zflai_lib.zsh"
local __db="$1" __table="$2" __array="$3[@]"
local __db="$1" __table="$2" __array="$3[@]" __table_resolved="$4"
local __db_dir="${DB_DEFS[${__db}_<access>_path]%/}" __db_file="${DB_DEFS[${__db}_<access>_file]}"
local __it __it2 __vn __ts __text
local __table_def_param_name
integer __have_table_def=0 idx coidx=1
local __table_resolved
-zflai_resolve "$__table" __table_resolved
__db_file="${__db_file//\%TABLE\%/$__table_resolved}"
__db_file="${__db_file//(#m)${~_xchg_pat_}/${_xchg_map_[$MATCH]}}"
local -a splitted keys
@ -33,8 +31,8 @@ local -a splitted keys
local first_key="${keys[1]}"
[[ "$first_key" = *time* ]] && shift keys || coidx=0
[[ -n "${DB_DEFS[${__db}_<hooks>_on_open]}" ]] && builtin print -r -- "${DB_DEFS[${__db}_<hooks>_on_open]//\%TABLE\%/$__table_resolved}" >>! "$__db_file"
[[ -n "${DB_DEFS[${__db}_<hooks>_on_open_sh]}" ]] && ( builtin cd -q "${DB_DEFS[${__db}_<access>_path]}" && eval "${DB_DEFS[${__db}_<hooks>_on_open_sh]}"; )
[[ -n "${DB_DEFS[${__db}_<hooks>_on_open]}" ]] && builtin print -r -- "${DB_DEFS[${__db}_<hooks>_on_open]//(#m)${~_xchg_pat_}/${_xchg_map_[$MATCH]}}" >>! "$__db_file"
[[ -n "${DB_DEFS[${__db}_<hooks>_on_open_sh]}" ]] && ( builtin cd -q "${DB_DEFS[${__db}_<access>_path]}" && eval "${DB_DEFS[${__db}_<hooks>_on_open_sh]//(#m)${~_xchg_pat_}/${_xchg_map_[$MATCH]}}"; )
for __it in "${(P)__array}"; do
splitted=( "${(@s:|:)__it}" )
@ -57,8 +55,8 @@ for __it in "${(P)__array}"; do
builtin print -r -- "$__text" >>! "$__db_file"
done
[[ -n "${DB_DEFS[${__db}_<hooks>_on_close]}" ]] && builtin print -r -- "${DB_DEFS[${__db}_<hooks>_on_close]//\%TABLE\%/$__table_resolved}" >>! "$__db_file"
[[ -n "${DB_DEFS[${__db}_<hooks>_on_close_sh]}" ]] && ( builtin cd -q "${DB_DEFS[${__db}_<access>_path]}" && eval "${DB_DEFS[${__db}_<hooks>_on_close_sh]}"; )
[[ -n "${DB_DEFS[${__db}_<hooks>_on_close]}" ]] && builtin print -r -- "${DB_DEFS[${__db}_<hooks>_on_close]//(#m)${~_xchg_pat_}/${_xchg_map_[$MATCH]}}" >>! "$__db_file"
[[ -n "${DB_DEFS[${__db}_<hooks>_on_close_sh]}" ]] && ( builtin cd -q "${DB_DEFS[${__db}_<access>_path]}" && eval "${DB_DEFS[${__db}_<hooks>_on_close_sh]//(#m)${~_xchg_pat_}/${_xchg_map_[$MATCH]}}"; )
return 0
# vim:ft=zsh:et

View file

@ -10,7 +10,7 @@
#
# It still needs resolution of the special keywords: %ID, %CN, %ESECS.
local entry tpe sel_db sel_table timestamp input priv_arr_name db_string key cause="$1"
local entry tpe sel_db sel_table sel_table_resolved timestamp input priv_arr_name db_string key cause="$1"
local -A priv_arr_map count_hash
integer priv_arr_index=0 arr_len entry_count=0
@ -50,6 +50,14 @@ for key in "${(k)count_hash[@]}"; do
done
[[ "$header" != "Routing " ]] && -zflai_run_log "${header%, }"
local -A _xchg_map_
_xchg_map_=(
"%TABLE%" "null"
"%ID%" "$ZUID_ID"
"%CN%" "$ZUID_CODENAME"
)
local _xchg_pat_="(%TABLE%|%ID%|%CN%)"
integer idx
for (( idx=1; idx <= priv_arr_index; ++ idx )); do
priv_arr_name="SUB_DATA_${idx}"
@ -57,12 +65,15 @@ for (( idx=1; idx <= priv_arr_index; ++ idx )); do
sel_db="${db_string%%__%__*}"
sel_table="${db_string##*__%__}"
-zflai_resolve "$sel_table" sel_table_resolved
_xchg_map_[%TABLE%]="$sel_table_resolved"
[[ "$db_string" = [[:space:]]# ]] && { print "ERROR: didn't find db_string for $priv_arr_name"; continue; }
if [[ "${DB_DEFS[${sel_db}_<access>_engine]}" = "sqlite3" ]]; then
-zflai_sqlite_store "$sel_db" "$sel_table" "$priv_arr_name"
elif [[ "${DB_DEFS[${sel_db}_<access>_engine]}" = "file" ]]; then
-zflai_file_store "$sel_db" "$sel_table" "$priv_arr_name"
-zflai_file_store "$sel_db" "$sel_table" "$priv_arr_name" "$sel_table_resolved"
elif [[ "${DB_DEFS[${sel_db}_<access>_engine]}" = "elastic-search" ]]; then
-zflai_elasticsearch_store "$sel_db" "$sel_table" "$priv_arr_name"
elif [[ "${DB_DEFS[${sel_db}_<access>_engine]}" = "mysql" ]]; then

View file

@ -11,6 +11,6 @@ path = %XDG_CACHE_HOME%/zflai/
on_open = STATUS: Opening file %TABLE%.log
on_open_sh =
on_close = STATUS: Closing file %TABLE%.log
on_close_sh =
on_close_sh = rm -f %TABLE%-*.nfo(N); touch %TABLE%-$(du -sh %TABLE%.log | tr '\t' ' ' | cut -d' ' -f1).nfo
; vim:ft=dosini