6 #-i insert, otherwise search
13 pkgfile=${ZPMDB:-/var/lib/zpm/local.db}
15 while getopts f:t:a:T:ijv opt; do
17 f) pkgfile="$OPTARG" ;;
18 t) target="$OPTARG" ;;
19 a) action="$OPTARG" ;;
20 T) timestamp="$OPTARG" ;;
24 *) printf '%s unknown option %s\n' "$0" "$opt" ; exit 1 ;;
29 if [ $op = 'insert' ]; then
31 cols='action,target,info';
32 if [ -n "$timestamp" ]; then
33 cols='ts,action,target,info'
36 printf "insert into zpmlog (%s)\n" $cols
38 if [ -n "$timestamp" ]; then
39 printf "'%s', " "$timestamp"
41 if [ -n "$action" ]; then
42 printf "'%s', " "$action"
46 if [ -n "$target" ]; then
47 printf "'%s', " "$target"
53 } | zpm shell $pkgfile
55 if [ $verbose -ne 0 ]; then
56 printf "%s %s %s\n" "$action" "$target" "$*" 1>&2
61 cols='ts,target,action,info'
63 if [ $op = 'search' ]; then
65 if [ $json -eq 1 ]; then
66 cols="json_group_array(json_object('ts',ts,'target',target,'action',action,'info',info))"
70 printf ".separator ' '\n"
71 printf 'select %s from zpmlog where\n' "$cols";
72 if [ -n "$timestamp" ]; then
73 printf "ts >= '%s' and " "$timestamp"
76 if [ -n "$action" ]; then
77 printf "action like '%s' and " "$action"
79 if [ -n "$target" ]; then
80 printf "target like '%s' and " "$target"
82 printf "true order by ts;\n"
83 } | zpm shell $pkgfile