Explorar el Código

Rudimentary support for table prefixing #1

Artur Welp hace 6 años
padre
commit
b57229f582
Se han modificado 3 ficheros con 19 adiciones y 0 borrados
  1. 2 0
      .gitignore
  2. 5 0
      src/Schema/Wrapper.php
  3. 12 0
      src/index.php

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+nbproject/
+.idea/

+ 5 - 0
src/Schema/Wrapper.php

@@ -57,6 +57,10 @@ class Wrapper{
 
     public static function get_table($name){
         $instance = self::getInstance();
+        echo $instance->_adapter->getConnection()->prefix;
+        if( $instance->_adapter->getConnection()->prefix ){
+            $name = $instance->_adapter->getConnection()->prefix . $name;
+        }
         return new Table($name, Array(), $instance->_adapter);
     }
 
@@ -72,6 +76,7 @@ class Wrapper{
 
     public static function exec($sql){
         $instance = self::getInstance();
+        $sql = preg_replace('/{(.*)}/', "$con->prefix$1", $sql);
         $instance->_driver->exec($sql);
     }
 

+ 12 - 0
src/index.php

@@ -0,0 +1,12 @@
+<?php
+
+include_once 'vendor/autoload.php';
+
+use Schema\Wrapper as Wrapper;
+
+$conn = new PDO("pgsql:dbname=urfat; user=urfat; password=urfat;host=127.0.0.1;port=5432");
+$conn->prefix = 'urfat_';
+Wrapper::set_driver($conn);
+
+$table = Wrapper::get_table('administrativo_pessoa');
+$table->drop();