Browse files

Added support for SQLite and Postgres

Also fixed a minor namespace issue.
  • Loading branch information...
1 parent 82fa58b commit 3a93a419d487c12c4d91ecab62c416257b72b529 @loic-sharma committed Jun 27, 2012
View
12 config/scaffold.php
@@ -4,18 +4,6 @@
/*
|--------------------------------------------------------------------------
- | Database Connection
- |--------------------------------------------------------------------------
- |
- | The name of the database connection to use when creating the scaffolds.
- | By default, the default database connection is used.
- |
- */
-
- 'connection' => Config::get('database.default'),
-
- /*
- |--------------------------------------------------------------------------
| View Parser
|--------------------------------------------------------------------------
|
View
2 libraries/drivers/driver.php
@@ -1,4 +1,4 @@
-<?php namespace scaffold\Drivers;
+<?php namespace Scaffold\Drivers;
use DB;
View
2 libraries/drivers/mysql.php
@@ -1,4 +1,4 @@
-<?php namespace scaffold\Drivers;
+<?php namespace Scaffold\Drivers;
use PDO;
View
21 libraries/drivers/postgres.php
@@ -1,8 +1,8 @@
-<?php namespace scaffold\Drivers;
+<?php namespace Scaffold\Drivers;
use PDO;
-class Postgres extends Driver {
+class Postgres extends Driver {
/**
* List all of the tables in the database.
@@ -21,5 +21,22 @@ public function all()
*/
public function fields($table)
{
+ $fields = array();
+
+ try
+ {
+ $columns = $this->pdo->query("SELECT * FROM information_schema.columns WHERE table_name = '$table'")->fetchAll(PDO::FETCH_ASSOC);
+
+ foreach ($columns as $column)
+ {
+ $fields[] = $column['column_name'];
+ }
+ }
+ catch (Exception $e)
+ {
+ throw new Exception($e->errorInfo[2]);
+ }
+
+ return $fields;
}
}
View
19 libraries/drivers/sqlite.php
@@ -1,4 +1,4 @@
-<?php namespace scaffold\Drivers;
+<?php namespace Scaffold\Drivers;
use PDO;
@@ -21,5 +21,22 @@ public function all()
*/
public function fields($table)
{
+ $fields = array();
+
+ try
+ {
+ $columns = $this->pdo->query("pragma table_info($table)")->fetchAll(PDO::FETCH_ASSOC);
+
+ foreach($columns as $column)
+ {
+ $fields[] = $column['name'];
+ }
+ }
+ catch (Exception $e)
+ {
+ throw new Exception($e->errorInfo[2]);
+ }
+
+ return $fields;
}
}
View
2 libraries/drivers/sqlserver.php
@@ -1,4 +1,4 @@
-<?php namespace scaffold\Drivers;
+<?php namespace Scaffold\Drivers;
use PDO;
View
2 libraries/table.php
@@ -1,4 +1,4 @@
-<?php namespace scaffold;
+<?php namespace Scaffold;
use DB;
View
12 start.php
@@ -2,11 +2,11 @@
Autoloader::map(array(
- 'scaffold\\Table' => __DIR__.DS.'libraries'.DS.'table.php',
+ 'Scaffold\\Table' => __DIR__.DS.'libraries'.DS.'table.php',
- 'scaffold\\Drivers\\Driver' => __DIR__.DS.'libraries'.DS.'drivers'.DS.'driver.php',
- 'scaffold\\Drivers\\MySQL' => __DIR__.DS.'libraries'.DS.'drivers'.DS.'mysql.php',
- 'scaffold\\Drivers\\Postgres' => __DIR__.DS.'libraries'.DS.'drivers'.DS.'driver.php',
- 'scaffold\\Drivers\\SQLite' => __DIR__.DS.'libraries'.DS.'drivers'.DS.'sqlite.php',
- 'scaffold\\Drivers\\SQLServer' => __DIR__.DS.'libraries'.DS.'drivers'.DS.'sqlserver.php',
+ 'Scaffold\\Drivers\\Driver' => __DIR__.DS.'libraries'.DS.'drivers'.DS.'driver.php',
+ 'Scaffold\\Drivers\\MySQL' => __DIR__.DS.'libraries'.DS.'drivers'.DS.'mysql.php',
+ 'Scaffold\\Drivers\\Postgres' => __DIR__.DS.'libraries'.DS.'drivers'.DS.'postgres.php',
+ 'Scaffold\\Drivers\\SQLite' => __DIR__.DS.'libraries'.DS.'drivers'.DS.'sqlite.php',
+ 'Scaffold\\Drivers\\SQLServer' => __DIR__.DS.'libraries'.DS.'drivers'.DS.'sqlserver.php',
));
View
8 tasks/make.php
@@ -5,13 +5,6 @@
class Scaffold_Make_Task {
/**
- * The database connection the scaffold will use.
- *
- * @var string
- */
- public $connection;
-
- /**
* The table's data.
*
* @var array
@@ -66,7 +59,6 @@ public function __construct()
*/
public function run($arguments)
{
- $this->connection = Config::get('scaffold::scaffold.connection');
$this->parser = Config::get('scaffold::scaffold.parser');
$count = count($arguments);

0 comments on commit 3a93a41

Please sign in to comment.