]> git.nbdom.net Git - nb.git/commitdiff
psql dump
authorNicolas Boisselier <nicolas.boisselier@semantico.com>
Tue, 21 Jun 2016 09:33:07 +0000 (10:33 +0100)
committerNicolas Boisselier <nicolas.boisselier@semantico.com>
Tue, 21 Jun 2016 09:33:07 +0000 (10:33 +0100)
lib/php/db.php
lib/php/db/types/pgsql.php
lib/postgres/functions.sql [new file with mode: 0644]

index b584459b6369f7c65d35f865c83bc6f406060364..12b21890e53626ba22bb6f2f524e81d41d63ae0d 100644 (file)
@@ -587,13 +587,13 @@ class Db extends nb {
 
     # Tables param filter
     $tables = $this->tables();
-    if ($table=self::p('table')) {
-      $new = array();
-      foreach (explode(',',$table) as $t) {
-        $new[$t] = $tables[$t];
-      }
-      $tables = $new;
-    }
+# NB 21.06.16     if ($table=self::p('table')) {
+# NB 21.06.16       $new = array();
+# NB 21.06.16       foreach (explode(',',$table) as $t) {
+# NB 21.06.16         $new[$t] = $tables[$t];
+# NB 21.06.16       }
+# NB 21.06.16       $tables = $new;
+# NB 21.06.16     }
     #if (NB_EOL == "\n")
 
     # Cache before changing db type
@@ -615,6 +615,9 @@ class Db extends nb {
       echo "-- Type     : ".self::p('db.type')."\n";
     }
 
+    $type = self::p('type','');
+    $name = self::p('name','');
+
     if ($sql = $this->type('exec')) {
       foreach ((is_array($sql) ? $sql : array($sql)) as $sql) {
         echo rtrim($sql,';').";\n";
@@ -623,6 +626,9 @@ class Db extends nb {
 
     foreach ($tables as $t) {
       if (!empty($tables) and empty($tables[$t->name])) continue;
+      if (!empty($type) and strpos($t->type,$type) === false) continue;
+      if (!empty($name) and strpos($t->name,$name) === false) continue;
+
       if ($insert) {
         echo "\n-- Table: ".$t->name."\n";
       }
index bd3221c0f61923901e3f14eb35bf46d07a77f2fb..3be9a54e7198e71d35b893900ae9cddfd83b852b 100644 (file)
@@ -9,6 +9,7 @@ $DB_TYPES['pgsql'] = array (
 'create' => function(&$field) {
   $r = array(
     '/datetime/i' => 'timestamp',
+    '/ COLLATE NOCASE/i' => '',
   );
   $field->type = preg_replace(array_keys($r),array_values($r),$field->type);
 },
diff --git a/lib/postgres/functions.sql b/lib/postgres/functions.sql
new file mode 100644 (file)
index 0000000..3dec9b3
--- /dev/null
@@ -0,0 +1,33 @@
+-- NB 21.06.16 CREATE AGGREGATE array_agg (anyelement)
+-- NB 21.06.16 (
+-- NB 21.06.16   sfunc = array_append,
+-- NB 21.06.16   stype = anyarray,
+-- NB 21.06.16   initcond = '{}'
+-- NB 21.06.16 );
+
+DROP AGGREGATE IF EXISTS CONCAT(text);
+CREATE AGGREGATE CONCAT(
+  basetype    = text,
+  sfunc       = textcat,
+  stype       = text,
+  initcond    = ''
+
+);
+
+CREATE OR REPLACE FUNCTION GROUP_CONCAT(anyarray, sep text DEFAULT ',', nullstr text DEFAULT '')
+RETURNS text AS $$
+SELECT array_to_string( ARRAY( SELECT coalesce(v::text, $3) FROM unnest($1) g(v) ), $2 )
+$$ LANGUAGE sql;
+
+DROP FUNCTION IF EXISTS CIDR_RANGE(cidr text, ip text);
+CREATE OR REPLACE FUNCTION CIDR_RANGE(cidr text, ip text)
+RETURNS bool AS $$
+SELECT ip::inet << cidr::cidr
+$$ LANGUAGE sql;
+
+-- NB 21.06.16 CREATE AGGREGATE GROUP_CONCAT(field,sep=',')
+-- NB 21.06.16   sfunc = array_append,
+-- NB 21.06.16   stype = anyarray,
+-- NB 21.06.16   initcond = '{}'
+-- NB 21.06.16   -- return array_to_string(array_agg(field),sep)
+-- NB 21.06.16 }