]> git.nbdom.net Git - nb.git/commitdiff
bin/dbq-vi
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 5 Sep 2024 22:38:41 +0000 (00:38 +0200)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 5 Sep 2024 22:38:41 +0000 (00:38 +0200)
bin/dbq-vi
www/dbq/dbq.php

index 96f510ca4623755768e3f8b19a41be8f1be3fbcc..769ec1c014417fc31b6a60a6db74b18f17a0a9d5 100755 (executable)
@@ -1,26 +1,10 @@
 #!/usr/bin/env bash
-tmp=/tmp/$USER-dbq-vi-$$
-
-_main() {
-       #exec echo $tmp
-       dbq.php "$1/vi/$2.sh" > "$tmp" || return
-
-       perl -i -pe 's/(\w+=".*?") /$1\n/g; s/;\s*$/\n/ ' "$tmp"
-
-       md5=$(md5sum "$tmp")
-
-       vi "$tmp"
-       [ -s "$tmp" ] || return 
-       [ "$md5" == "$(md5sum "$tmp")" ] && return 
-       bash -f "$tmp" || return
-       #echo $md5 " == $(md5sum "$tmp")"
-
-       eval dbq.php $1/update/ format=yaml $(cat "$tmp")
-
-}
+tmp=/tmp/$USER-dbq-vi-$$.yaml
 
 main() {
        #exec echo $tmp
+       path="$1"
+       id="$2"
        cat <<EOF > "$tmp"
 #
 # dbq-vi
@@ -28,7 +12,13 @@ main() {
 #
 EOF
 
-       dbq.php "$1/vi/$2.yaml" >> "$tmp" || return
+       if [ -z "$id" ]
+       then
+               dbq.php "$path/add.yaml" >> "$tmp" || return
+               sed -i -e 's/"//g' "$tmp"
+       else
+               dbq.php "$path/vi/$id.yaml" >> "$tmp" || return
+       fi
        md5=$(md5sum "$tmp")
 
        vi "$tmp"
@@ -37,7 +27,12 @@ EOF
        [ "$md5" == "$(md5sum "$tmp")" ] && return 
        #echo $md5 " == $(md5sum "$tmp")"
 
-       dbq.php $1/update.yaml __YAML__="$tmp"
+       if [ -z "$id" ]
+       then
+               dbq.php $path/insert.yaml __YAML__="$tmp"
+       else
+               dbq.php $path/update.yaml __YAML__="$tmp"
+       fi
 
 }
 
index 98dc6185ca449b626d9fe3b822ea456d0eba9ff8..88d27af3b0114784a926b83c10882211b0d6deb5 100644 (file)
@@ -502,8 +502,18 @@ class DbQ extends nb {
                #debug([count($keys),$keys,count($values),$values]);
                $values = array_combine($keys,$values);
 
+               if ($add and (0
+                       or $this->params['format'] == 'yaml'
+                       or $this->params['format'] == 'json'
+               )) {
+                       foreach ($this->table->fields() as $field) {
+                               $fields[$field->name] = '';
+                       }
+                       $this->db->out($fields);
+                       return;
+
                # Handle format for /vi 
-               if ($this->params['format'] != $this->format_html) {
+               } elseif ($this->params['format'] != $this->format_html) {
 
                        #debug($values);
                        $row = $this->db->query2h($this->table->html_edit_sql($values));