6 #-i insert, otherwise search
13 pkgfile=${ZPMDB:-/var/lib/zpm/local.db}
17 while getopts f:t:a:T:ijvr opt; do
19 f) pkgfile="$OPTARG" ;;
20 t) target="$OPTARG" ;;
21 a) action="$OPTARG" ;;
22 T) timestamp="$OPTARG" ;;
27 *) printf '%s unknown option %s\n' "$0" "$opt" ; exit 1 ;;
32 if [ $op = 'insert' ]; then
34 cols='action,target,info';
35 if [ -n "$timestamp" ]; then
36 cols='ts,action,target,info'
39 printf "insert into zpmlog (%s)\n" $cols
41 if [ -n "$timestamp" ]; then
42 printf "'%s', " "$timestamp"
44 if [ -n "$action" ]; then
45 printf "'%s', " "$action"
49 if [ -n "$target" ]; then
50 printf "'%s', " "$target"
56 } | zpm shell $pkgfile
58 if [ $verbose -ne 0 ]; then
59 printf "%s %s %s\n" "$action" "$target" "$*" 1>&2
64 cols='ts,target,action,info'
66 if [ $op = 'search' ]; then
68 if [ $json -eq 1 ]; then
69 cols="json_group_array(json_object('ts',ts,'target',target,'action',action,'info',info))"
73 printf ".separator ' '\n"
74 printf 'select %s from zpmlog where\n' "$cols";
75 if [ -n "$timestamp" ]; then
76 printf "ts >= '%s' and " "$timestamp"
79 if [ -n "$action" ]; then
80 printf "action like '%s' and " "$action"
82 if [ -n "$target" ]; then
83 printf "target like '%s' and " "$target"
85 printf "true order by ts $order;\n"
86 } | zpm shell $pkgfile