Skip to content

Commit bc02ecf

Browse files
committed
Fixed PostgreSQL support
1 parent 6f1c835 commit bc02ecf

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/Entity.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,18 @@ public function __call(?string $method = null, array $params = [])
5151
public function getScheme(): array
5252
{
5353
if (null === $this->scheme) {
54-
$raw = $this->medoo->query('DESCRIBE '.$this->getTable())->fetchAll();
54+
switch ($this->config('medoo.database_type')) {
55+
case 'pgsql':
56+
$query = 'SELECT column_name AS "Field" FROM information_schema.COLUMNS WHERE table_name=\''.$this->getTable().'\'';
57+
break;
58+
default:
59+
$query = 'DESCRIBE '.$this->getTable();
60+
break;
61+
}
62+
$raw = $this->medoo->query($query)->fetchAll();
5563
$this->scheme = [];
5664
foreach ($raw as $field) {
57-
$this->scheme[$field['Field']] = $field;
65+
$this->scheme[] = $field['Field'];
5866
}
5967
}
6068

@@ -76,13 +84,12 @@ public function save(bool $validate = true): self
7684
throw new Exception('Entity '.$this->__getEntityName().' data is not valid');
7785
}
7886

79-
/**
87+
/*
8088
* Remove fields that not exists in DB table scheme,
8189
* to avoid thrown exceptions on saving garbadge fields.
8290
*/
83-
$scheme = \array_keys($this->getScheme());
8491
foreach ($this->data as $key => $value) {
85-
if (!\in_array($key, $scheme, true)) {
92+
if (!\in_array($key, $this->getScheme(), true)) {
8693
unset($this->data[$key]);
8794
}
8895
}

0 commit comments

Comments
 (0)