method getCreateKeys documentation in bbn\Db\Languages\Pgsql
function(string $table, array $model = NULL)
{
$st = '';
if (!$model) {
$model = $this->modelize($table);
}
if ($model && !empty($model['keys'])) {
$st .= 'ALTER TABLE ' . $this->escape($table) . PHP_EOL;
$last = count($model['keys']) - 1;
$i = 0;
foreach ($model['keys'] as $name => $key) {
if (!empty($key['unique'])
&& isset($model['fields'][$key['columns'][0]])
&& ($model['fields'][$key['columns'][0]]['key'] === 'PRI')
) {
$st .= 'ADD PRIMARY KEY';
} elseif (!empty($key['unique'])) {
$st .= 'ADD CONSTRAINT ' . $this->escape($name) . ' UNIQUE';
} else {
$i++;
continue;
}
$st .= ' (' . implode(
',', array_map(
function ($a) {
return $this->escape($a);
}, $key['columns']
)
) . ')';
$st .= $i === $last ? ';' : ',' . PHP_EOL;
$i++;
}
}
return trim($st, ',' . PHP_EOL);
}
BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way
This website uses cookies to ensure you get the best experience on our website.
© 2011-2025
BBN Solutions