]> git.nbdom.net Git - nb.git/commitdiff
nb::ar_map and function out() format csv
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 29 Feb 2016 01:44:28 +0000 (01:44 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 29 Feb 2016 01:44:28 +0000 (01:44 +0000)
lib/php/db.php
lib/php/nb.php

index 52e6467ebc9c043e86509274d5f726494d3e9223..552caa7afd13ba53d8f4e5453886ffbce70f792a 100644 (file)
@@ -373,6 +373,18 @@ EOF;
     #echo $v.PHP_EOL;
     #bye($f); return true;
     if ($f == 'json') { echo json_encode($v).PHP_EOL; }
+    #elseif ($f == 'csv' and is_array($v)) { echo join("\n",$v)."\n"; }
+    #elseif ($f == 'csv') { echo join("\t",nb::ar_map('json_encode($a)',$v))."\n"; }
+    #elseif ($f == 'csv') { echo json_encode($v).PHP_EOL; }
+    elseif ($f == 'csv') {
+      #if (is_object($row)) echo "$row\n";
+      #$isHash = array_values($v) !== $v;
+      foreach ($v as $row) {
+        if (is_scalar($row)) echo "$row\n";
+        else echo join("\t",array_values($row))."\n";
+      }
+      #echo json_encode($v).PHP_EOL;
+    }
     elseif (preg_match('/yaml|yml/',$f)) { echo $this->yaml_encode($v); }
     elseif (preg_match('/php|var_export/',$f)) { echo var_export($v,true); }
     elseif (preg_match('/var_dump/',$f)) { echo var_dump($v,true); }
@@ -391,6 +403,9 @@ EOF;
     if ($action == 'tables') {
       return $this->out($this->tables());
 
+    } elseif ($action == 'dbs') {
+      return $this->out($this->dbs);
+
     } elseif ($action == 'html_menu') {
       $this->print_header($this->p('format','html'));
       echo $this->html_menu();
index 77292b91258710debaa29357d8603dea5523aeb5..ca02fba135ec85eac93470bcdaf3e6a14262fa33 100644 (file)
@@ -60,6 +60,14 @@ class nb {
     return debug($msg,$level);
   }
 
+  /*
+   * Function: ar_map
+   * Does what it says
+   */
+  static function ar_map($text) {
+    return ar_map($text);
+  }
+
   /*
    * Function: prettyText
    * Does what it says