6 #-i insert, otherwise search
12 pkgfile=${ZPMDB:-/var/lib/zpm/local.db}
14 while getopts f:t:a:T:ij opt; do
16 f) pkgfile="$OPTARG" ;;
17 t) target="$OPTARG" ;;
18 a) action="$OPTARG" ;;
19 T) timestamp="$OPTARG" ;;
22 *) printf '%s unknown option %s\n' "$0" "$opt" ; exit 1 ;;
27 if [ $op = 'insert' ]; then
29 cols='action,target,info';
30 if [ -n "$timestamp" ]; then
31 cols='ts,action,target,info'
34 printf "insert into zpmlog (%s)\n" $cols
36 if [ -n "$timestamp" ]; then
37 printf "'%s', " "$timestamp"
39 if [ -n "$action" ]; then
40 printf "'%s', " "$action"
44 if [ -n "$target" ]; then
45 printf "'%s', " "$target"
51 } | zpm shell $pkgfile
55 cols='ts,target,action,info'
57 if [ $op = 'search' ]; then
59 if [ $json -eq 1 ]; then
60 cols="json_group_array(json_object('ts',ts,'target',target,'action',action,'info',info))"
64 printf ".separator ' '\n"
65 printf 'select %s from zpmlog where\n' "$cols";
66 if [ -n "$timestamp" ]; then
67 printf "ts >= '%s' and " "$timestamp"
70 if [ -n "$action" ]; then
71 printf "action like '%s' and " "$action"
73 if [ -n "$target" ]; then
74 printf "target like '%s' and " "$target"
76 printf "true order by ts;\n"
77 } | zpm shell $pkgfile