]> git.nbdom.net Git - nb.git/commitdiff
Bed
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 7 Apr 2016 23:52:03 +0000 (00:52 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 7 Apr 2016 23:52:03 +0000 (00:52 +0100)
etc/dbs.php [new file with mode: 0644]
lib/php/db.php
lib/php/db/index.php
lib/php/out.php

diff --git a/etc/dbs.php b/etc/dbs.php
new file mode 100644 (file)
index 0000000..c82782a
--- /dev/null
@@ -0,0 +1,174 @@
+<?php
+/*
+*/
+$CONF = array (
+  'rent' => array (
+    'order' => 1,
+    'pdo' => 'sqlite:/opt/rent/rent.db',
+    'title' => 'Rent',
+    'notice' => 'Micro foncier 4BE',
+    'default_table' => 'rent',
+    'tables' => array (
+      'place' => array (
+        'replace' => array (
+          'id' => 'addr.addr',
+        ),
+      ),
+      'rent' => array (
+        'order_by' => 'start desc',
+        'replace' => array (
+          'idtenant' => 'tenant.name',
+          'idplace' => 'addr.addr',
+        ),
+        'extras' => array (
+          'total' => array (
+            'type' => 'float(8,2)',
+            'extra' => 'ROUND(rent+charge,2)',
+          ),
+          'rent_year' => array (
+            'type' => 'float(8,2)',
+            'extra' => 'rent * (1 + ( strftime(\'%m\',end)+12*strftime(\'%Y\',end) ) -  ( strftime(\'%m\',start)+12*strftime(\'%Y\',start) ))',
+          ),
+        ),
+      ),
+    ),
+    'name' => 'rent',
+  ),
+  'ui-mem' => array (
+    'pdo' => 'sqlite:/dev/shm/semantico.db',
+    'title' => 'Semantico UI',
+    'default_table' => 'node',
+    'tables' => array (
+      'node' => array (
+        'order_by' => '(SELECT value FROM fact WHERE idnode=id AND name=\'date_install\') DESC',
+        'replace_' => array (
+          'iddc' => 'dc.id',
+        ),
+      ),
+    ),
+    'replace' => array (
+      'SELECT name FROM dc WHERE id=\'@id\'' => '.node td.iddc',
+    ),
+    'name' => 'ui-mem',
+  ),
+  'rt' => array (
+    'pdo' => 'pgsql:host=db.rt.semantico.net;port=5432;dbname=rtdb;user=rtuser;password=',
+    'title' => 'RT',
+    'password' => 'scrubchug',
+    'name' => 'rt',
+  ),
+  'ui' => array (
+    'pdo' => 'sqlite:/opt/semantico/product/releases/sem_ui/db/semantico.db',
+    'title' => 'Semantico UI',
+    'default_table' => 'node',
+    'tables' => array (
+      'node' => array (
+        'order_by' => '(SELECT value FROM fact WHERE idnode=id AND name=\'date_install\') DESC',
+        'replace_' => array (
+          'iddc' => 'dc.id',
+        ),
+      ),
+    ),
+    'replace' => array (
+      'SELECT name FROM dc WHERE id=\'@id\'' => '.node td.iddc',
+    ),
+    'name' => 'ui',
+  ),
+  'postfix' => array (
+    'title' => 'Postfix on Izideal',
+    'host' => 'media.izideal.vpn',
+    'user' => 'postfix',
+    'password' => 'dx7d50nfs',
+    'type' => 'mysql',
+    'name' => 'postfix',
+  ),
+  'izidev' => array (
+    'host' => 'big.cascais.loc',
+    'title' => 'Mysql Izi on Big',
+    'password' => 'mpc60ax73',
+    'default_table' => 'process',
+    'user' => 'nico',
+    'name' => 'izi',
+    'tables' => array (
+      'site' => array (
+        'replace' => array (
+          'idlang' => 'lang.id',
+        ),
+      ),
+    ),
+    'type' => 'mysql',
+  ),
+  'wp' => array (
+    'host' => 'admin.izideal.vpn',
+    'user' => 'nico',
+    'password' => 'mpc60ax73',
+    'type' => 'mysql',
+    'name' => 'wp',
+  ),
+  'nb' => array (
+    'host' => 'admin.izideal.vpn',
+    'user' => 'nico',
+    'password' => 'mpc60ax73',
+    'type' => 'mysql',
+    'name' => 'nb',
+    'tables' => array(
+      
+    ),
+  ),
+  'puppetdb' => array (
+    'title' => 'Puppetdb',
+    'host' => 'big',
+    'type' => 'pgsql',
+    'user' => 'puppetdb',
+    'default_table' => 'view_hosts',
+    'tables' => array (
+      'hosts' => array (
+        'extras' => array (
+          'last_compile' => array (
+            'type' => 'text',
+            'extra' => 'to_char(hosts.last_compile, \'YYYY-MM-DD HH:mm:ss\'::text)',
+          ),
+          'last_freshcheck' => array (
+            'type' => 'text',
+            'extra' => 'to_char(hosts.last_freshcheck, \'YYYY-MM-DD HH:mm:ss\'::text)',
+          ),
+          'updated_at' => array (
+            'type' => 'text',
+            'extra' => 'to_char(hosts.updated_at, \'YYYY-MM-DD HH:mm:ss\'::text)',
+          ),
+          'created_at' => array (
+            'type' => 'text',
+            'extra' => 'to_char(hosts.created_at, \'YYYY-MM-DD HH:mm:ss\'::text)',
+          ),
+          'test' => array (
+            'type' => 'int',
+            'extra' => 1,
+          ),
+        ),
+      ),
+    ),
+    'password' => 'puppetdb6073/!',
+    'name' => 'puppetdb',
+  ),
+  'izi' => array (
+    'title' => 'Mysql Izi on Admin',
+    'default_table' => 'process',
+    'host' => 'admin.izideal.vpn',
+    'user' => 'izideal',
+    'name' => 'izi',
+    'tables' => array (
+      'site' => array (
+        'replace' => array (
+          'idlang' => 'lang.id',
+        ),
+      ),
+    ),
+    'password' => 'dx7d50nfs',
+    'type' => 'mysql',
+  ),
+  'crypt' => array (
+    'pdo' => 'sqlite:/dev/shm/crypt.db',
+    'name' => 'crypt',
+  ),
+);
+?>
index e62bb7912bd823974e4bdba1c4998e38a2bc7cde..2ea82d19a6186fcbfc67aec4e5c6eb43b283d27b 100644 (file)
@@ -35,7 +35,6 @@ class Db extends nb {
 # NB 28.03.16   public $table;
 
   # Web
-  public $dbs; // others databases keys
   public $default_table;
   public $sort;
   public $extras;
@@ -498,20 +497,18 @@ EOF;
           $return = true;
 
         } elseif ($action == 'db.tables' or $action == 'tables') {
-          foreach ($this->tables() as $t) {
-            $rows[] = $t->infos();
-          }
+          foreach ($this->tables() as $t) { $rows[] = $t->infos(); }
           $return = $this->out2($rows);
 
         } elseif ($action == 'db.dbs' or $action == 'dbs') {
-          $return = $this->out2($this->dbs,"name");
+          if (self::p('hash')) $return = $this->out2($this->conf);
+          else $return = $this->out2($this->dbs,"name");
 
         } elseif (preg_match('/^db\.(\w+)/',$action,$m)) {
           if ($rows = $this->$m[1]()) $return = $this->out2($rows,(is_scalar($rows) ? $m[1] : array()));
 
         } elseif($table) {
           if ($r=$table->action($action)) $return = $r;
-          #if (!is_scalar($return)) $return = $this->out2($return);
 
         }
     }
@@ -533,17 +530,21 @@ EOF;
       if (is_scalar($files)) $files = array($files);
 
     foreach ($files as $file) {
-      if (is_readable($file) and ($yaml = yaml_parse_file($file))) {
-        #foreach ($yaml as $k=>$v) { $yaml[$k]['_conf_dbs'] = $file; }
-        #debug($file);
+      if (!is_readable($file)) continue;
+
+      if (preg_match('/\.(yaml|yml)$/i',$file) and ($yaml = yaml_parse_file($file))) {
         $h = array_replace_recursive($h,$yaml);
+
+      } elseif (preg_match('/\.php$/i',$file)) {
+        #global $VAR1;
+        require($file);
+        if (!empty($CONF)) $h = $CONF;
+
       }
-        #debug($file);
-      #if ( ($yaml = @yaml_parse_file($file)) ) $h = array_replace_recursive($h,$yaml)
-      ;
-      #}
+
+      #if ( ($yaml = @yaml_parse_file($file)) ) $h = array_replace_recursive($h,$yaml);
     }
-    unset($yaml);
+    unset($yaml,$CONF);
 
     # Emulate hash pointer _import
     foreach ($h as $db=>$o) {
@@ -613,7 +614,10 @@ EOF;
     # Connection
     #bye($Db->p('db'));
     if (!isset($dbs[$Db->p('db')])) $Db->bye("Can't find db: `".$Db->p('db')."` in `".join(",",array_keys($dbs))."`",false);
-    $db = array_merge($dbs[$Db->p('db')],array('dbs'=>array_keys($dbs)));
+    $db = array_merge($dbs[$Db->p('db')],array(
+      'dbs'=>array_keys($dbs),
+      'conf'=>$dbs,
+    ));
 
     $Db->__construct($db);
 
index 5fbeef32993f8d042100023e675d30c3ab963984..6a528f7d6c94959223e650e897db64dcdb0db42c 100755 (executable)
@@ -8,6 +8,17 @@
 */
 require_once(dirname(__FILE__).'/../config.php');
 require_once(dirname(__FILE__).'/../db.php');
+/*
+# TODO - NB 08.04.16
+$aliases = array(
+  'd' => 'db',
+  't' => 'table',
+  'f' => 'format',
+  'l' => 'limit',
+  'a' => 'action',
+  'h' => 'header',
+);
+*/
 
 #bye(out::client_type());
 Db::pdef('format',out::client_type());
@@ -18,10 +29,12 @@ if (preg_match('/^(\w+)\.(.*?)$/',Db::p('table'),$m)) {
   Db::pset('db',$m[1]);
   Db::pset('table',$m[2]);
 }
+
+if(defined('DB_NO_INIT')) return true;
 #bye(Db::conf_dbs(array( Db::ROOT_DIR.'/etc/dbs.yaml','/etc/dbs.yaml' )));
 #$conf = Db::conf_dbs(array( Db::ROOT_DIR.'/etc/dbs.yaml','/etc/dbs.yaml' )); Db::init($conf);
-Db::init(array( Db::ROOT_DIR.'/etc/dbs.yaml','/etc/dbs.yaml' ));
+Db::init(array( Db::ROOT_DIR.'/etc/dbs.yaml',Db::ROOT_DIR.'/etc/dbs.php','/etc/dbs.yaml' ));
 
-if( defined('DB_NO_ACTION')) return true;
+if(defined('DB_NO_ACTION')) return true;
 return $Db->action($Table);
 ?>
index b8f597c9cbb32ef11d4c8c81cfec8d6085fd3a7e..d53b177531c3542f5d1634f6593592d2d4041f1d 100644 (file)
@@ -8,8 +8,24 @@ Class Out extends Nb {
   public static $type;
   public static function init() {
     self::$types = array(
-      'sql' => array(
+      'sql' => array(),
+
+      #'php' => array( 'function' => function(&$r) {var_dump($r);},),
+      'php' => array(
+        #'enclose' => array('$VAR=array(',');'),
+        'enclose' => array('$CONF = ',';'),
+        #'eol' => NB_EOL,
+        'rec' => ',',
+        #'function' => function(&$r) { echo preg_replace('/[\r\n]/','',var_dump($r,true));},
+        #'function' => function(&$r) {print_r($r);}
+        #'function' => function(&$r) {var_dump($r);}
+        'function' => function(&$r) { echo preg_replace('/(=>\s*)\n\s+/m','\1',var_export($r,true));}
+        #'function' => function(&$r) { echo preg_replace('/\n/','',var_export($r,true));}
+        #'function' => function(&$r) {var_export($r);}
       ),
+      #'var_dump' => array( 'function' => function(&$r) {var_dump($r);},),
+      #'print_r' => array( 'function' => function(&$r) {print_r($r);},),
+      #'var_export' => array( 'function' => function(&$r) {var_export($r);},),
 
       'div' => array(
         'is_html' => true,
@@ -153,7 +169,7 @@ Class Out extends Nb {
 
     # Defined function
     if (isset($o['function'])) {
-      if (preg_match('/^out_/',$o['function'])) {
+      if (is_scalar($o['function']) and preg_match('/^out_/',$o['function'])) {
         $o['function']($row,$o);
       } else {
         echo $o['function']($row);