db = Pgsql::with($pgsql); } protected Pgsql $db; function db(): Pgsql { return $this->db; } const PRIMARY_KEY_DEFINITION = [ "id_" => "serial primary key", ]; function _getMigration(CapacitorChannel $channel): _pgsqlMigration { return new _pgsqlMigration(cl::merge([ $this->_createSql($channel), ], $channel->getMigration()), $channel->getName()); } function _getCreateSql(CapacitorChannel $channel): string { $query = new _pgsqlQuery($this->_createSql($channel)); return self::format_sql($channel, $query->getSql()); } protected function _addToChannelsSql(CapacitorChannel $channel): array { return cl::merge(parent::_addToChannelsSql($channel), [ "suffix" => "on conflict (name) do nothing", ]); } function _exists(CapacitorChannel $channel): bool { $tableName = $channel->getTableName(); if (($index = strpos($tableName, ".")) !== false) { $schemaName = substr($tableName, 0, $index); $tableName = substr($tableName, $index + 1); } else { $schemaName = "public"; } return null !== $this->db->get([ "select tablename from pg_tables", "where" => [ "schemaname" => $schemaName, "tablename" => $tableName, ], ]); } function close(): void { $this->db->close(); } }