Skip to content

Commit

Permalink
Merge pull request #9 from MetaDone/pgsql-get-cols
Browse files Browse the repository at this point in the history
Add PostgreSQL support
  • Loading branch information
kEpEx authored Nov 22, 2016
2 parents 43435b6 + a8ca8d2 commit c6a0701
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/CrudGeneratorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,28 @@ public function Generate()


protected function getColumns($tablename) {
$cols = DB::select("show columns from ".$tablename);
$dbType = DB::getDriverName();
switch ($dbType) {
case "pgsql":
$cols = DB::select("select column_name as Field, "
. "data_type as Type, "
. "is_nullable as Null "
. "from INFORMATION_SCHEMA.COLUMNS "
. "where table_name = '" . $tablename . "'");
break;
default:
$cols = DB::select("show columns from " . $tablename);
break;
}

$ret = [];
foreach ($cols as $c) {
$field = isset($c->Field) ? $c->Field : $c->field;
$type = isset($c->Type) ? $c->Type : $c->type;
$cadd = [];
$cadd['name'] = $c->Field;
$cadd['type'] = $c->Field == 'id' ? 'id' : $this->getTypeFromDBType($c->Type);
$cadd['display'] = ucwords(str_replace('_', ' ', $c->Field));
$cadd['name'] = $field;
$cadd['type'] = $field == 'id' ? 'id' : $this->getTypeFromDBType($type);
$cadd['display'] = ucwords(str_replace('_', ' ', $field));
$ret[] = $cadd;
}
return $ret;
Expand Down

0 comments on commit c6a0701

Please sign in to comment.