]> pd.if.org Git - zpackage/commitdiff
add json to sqlite
authorNathan Wagner <nw@hydaspes.if.org>
Thu, 25 Oct 2018 13:37:52 +0000 (13:37 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Sat, 3 Nov 2018 12:39:52 +0000 (12:39 +0000)
add json output option to zpm-log

sqlite/config.h
zpm-log

index 3ef85f9beb200eb6e5e4a91703b168f7aff4a779..2667358f9f131ab67a68882249febe9608131eef 100644 (file)
@@ -14,3 +14,5 @@
 #ifdef __APPLE__
 #define OSATOMIC_USE_INLINED 1
 #endif
+
+#define SQLITE_ENABLE_JSON1 1
diff --git a/zpm-log b/zpm-log
index f4fdab87ca64158a2ebfa6c82cdfae046ba37314..8e53f6204060edffb64d0889cb2e62d61f35c993 100755 (executable)
--- a/zpm-log
+++ b/zpm-log
@@ -6,17 +6,19 @@
 #-i insert, otherwise search
 
 op=search
-action='log'
+action=
+json=0
 
 pkgfile=${ZPMDB:-/var/lib/zpm/local.db}
 
-while getopts f:t:a:T:i opt; do
+while getopts f:t:a:T:ij opt; do
        case $opt in
                f) pkgfile="$OPTARG" ;;
                t) target="$OPTARG" ;;
                a) action="$OPTARG" ;;
                T) timestamp="$OPTARG" ;;
                i) op=insert ;;
+               j) json=1 ;;
                *) printf '%s unknown option %s\n' "$0" "$opt" ; exit 1 ;;
        esac
 done
@@ -50,21 +52,28 @@ if [ $op = 'insert' ]; then
 
 fi
 
+cols='ts,target,action,info'
+
 if [ $op = 'search' ]; then
+
+if [ $json -eq 1 ]; then
+       cols="json_group_array(json_object('ts',ts,'target',target,'action',action,'info',info))"
+fi
+
 {
-       printf 'select ts,action,target,info from zpmlog where\n';
+       printf ".separator ' '\n"
+       printf 'select %s from zpmlog where\n' "$cols";
        if [ -n "$timestamp" ]; then
                printf "ts >= '%s' and " "$timestamp"
        fi
 
        if [ -n "$action" ]; then
-               printf "action = '%s' and " "$action"
+               printf "action like '%s' and " "$action"
        fi
        if [ -n "$target" ]; then
-               printf "target = '%s' and " "$target"
+               printf "target like '%s' and " "$target"
        fi
-       printf "true;\n"
+       printf "true order by ts;\n"
 } | zpm shell $pkgfile
 
 fi
-