Skip to content

Commit

Permalink
Update packages, just nette/database (#322)
Browse files Browse the repository at this point in the history
 - nette/database updated from v3.2.0 to v3.2.1 patch
   See changes: nette/database@v3.2.0...v3.2.1
   Release notes: https://github.com/nette/database/releases/tag/v3.2.1

Replace #316
  • Loading branch information
spaze authored May 8, 2024
2 parents 6ac01b5 + 7629ef9 commit 8294231
Show file tree
Hide file tree
Showing 17 changed files with 390 additions and 37 deletions.
12 changes: 6 additions & 6 deletions site/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions site/vendor/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@
'Nette\\Database\\Conventions\\AmbiguousReferenceKeyException' => $vendorDir . '/nette/database/src/Database/Conventions/AmbiguousReferenceKeyException.php',
'Nette\\Database\\Conventions\\DiscoveredConventions' => $vendorDir . '/nette/database/src/Database/Conventions/DiscoveredConventions.php',
'Nette\\Database\\Conventions\\StaticConventions' => $vendorDir . '/nette/database/src/Database/Conventions/StaticConventions.php',
'Nette\\Database\\DateTime' => $vendorDir . '/nette/database/src/Database/DateTime.php',
'Nette\\Database\\Driver' => $vendorDir . '/nette/database/src/Database/Driver.php',
'Nette\\Database\\DriverException' => $vendorDir . '/nette/database/src/Database/DriverException.php',
'Nette\\Database\\Drivers\\MsSqlDriver' => $vendorDir . '/nette/database/src/Database/Drivers/MsSqlDriver.php',
Expand All @@ -425,6 +426,11 @@
'Nette\\Database\\IStructure' => $vendorDir . '/nette/database/src/Database/IStructure.php',
'Nette\\Database\\ISupplementalDriver' => $vendorDir . '/nette/database/src/compatibility-intf.php',
'Nette\\Database\\NotNullConstraintViolationException' => $vendorDir . '/nette/database/src/Database/exceptions.php',
'Nette\\Database\\Reflection' => $vendorDir . '/nette/database/src/Database/Reflection.php',
'Nette\\Database\\Reflection\\Column' => $vendorDir . '/nette/database/src/Database/Reflection/Column.php',
'Nette\\Database\\Reflection\\ForeignKey' => $vendorDir . '/nette/database/src/Database/Reflection/ForeignKey.php',
'Nette\\Database\\Reflection\\Index' => $vendorDir . '/nette/database/src/Database/Reflection/Index.php',
'Nette\\Database\\Reflection\\Table' => $vendorDir . '/nette/database/src/Database/Reflection/Table.php',
'Nette\\Database\\ResultSet' => $vendorDir . '/nette/database/src/Database/ResultSet.php',
'Nette\\Database\\Row' => $vendorDir . '/nette/database/src/Database/Row.php',
'Nette\\Database\\SqlLiteral' => $vendorDir . '/nette/database/src/Database/SqlLiteral.php',
Expand Down
6 changes: 6 additions & 0 deletions site/vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ class ComposerStaticInit247de957f14f643f393d210a332dd05b
'Nette\\Database\\Conventions\\AmbiguousReferenceKeyException' => __DIR__ . '/..' . '/nette/database/src/Database/Conventions/AmbiguousReferenceKeyException.php',
'Nette\\Database\\Conventions\\DiscoveredConventions' => __DIR__ . '/..' . '/nette/database/src/Database/Conventions/DiscoveredConventions.php',
'Nette\\Database\\Conventions\\StaticConventions' => __DIR__ . '/..' . '/nette/database/src/Database/Conventions/StaticConventions.php',
'Nette\\Database\\DateTime' => __DIR__ . '/..' . '/nette/database/src/Database/DateTime.php',
'Nette\\Database\\Driver' => __DIR__ . '/..' . '/nette/database/src/Database/Driver.php',
'Nette\\Database\\DriverException' => __DIR__ . '/..' . '/nette/database/src/Database/DriverException.php',
'Nette\\Database\\Drivers\\MsSqlDriver' => __DIR__ . '/..' . '/nette/database/src/Database/Drivers/MsSqlDriver.php',
Expand All @@ -628,6 +629,11 @@ class ComposerStaticInit247de957f14f643f393d210a332dd05b
'Nette\\Database\\IStructure' => __DIR__ . '/..' . '/nette/database/src/Database/IStructure.php',
'Nette\\Database\\ISupplementalDriver' => __DIR__ . '/..' . '/nette/database/src/compatibility-intf.php',
'Nette\\Database\\NotNullConstraintViolationException' => __DIR__ . '/..' . '/nette/database/src/Database/exceptions.php',
'Nette\\Database\\Reflection' => __DIR__ . '/..' . '/nette/database/src/Database/Reflection.php',
'Nette\\Database\\Reflection\\Column' => __DIR__ . '/..' . '/nette/database/src/Database/Reflection/Column.php',
'Nette\\Database\\Reflection\\ForeignKey' => __DIR__ . '/..' . '/nette/database/src/Database/Reflection/ForeignKey.php',
'Nette\\Database\\Reflection\\Index' => __DIR__ . '/..' . '/nette/database/src/Database/Reflection/Index.php',
'Nette\\Database\\Reflection\\Table' => __DIR__ . '/..' . '/nette/database/src/Database/Reflection/Table.php',
'Nette\\Database\\ResultSet' => __DIR__ . '/..' . '/nette/database/src/Database/ResultSet.php',
'Nette\\Database\\Row' => __DIR__ . '/..' . '/nette/database/src/Database/Row.php',
'Nette\\Database\\SqlLiteral' => __DIR__ . '/..' . '/nette/database/src/Database/SqlLiteral.php',
Expand Down
14 changes: 7 additions & 7 deletions site/vendor/composer/installed.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions site/vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@
'dev_requirement' => false,
),
'nette/database' => array(
'pretty_version' => 'v3.2.0',
'version' => '3.2.0.0',
'reference' => '39f98a8c5a0e67d30424ca199e0630b678bcecd5',
'pretty_version' => 'v3.2.1',
'version' => '3.2.1.0',
'reference' => '1d9e2866d711ce16a94bd9c98abaf8378269cef6',
'type' => 'library',
'install_path' => __DIR__ . '/../nette/database',
'aliases' => array(),
Expand Down
9 changes: 9 additions & 0 deletions site/vendor/nette/database/src/Database/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public function __construct(
private readonly ?string $password = null,
private readonly array $options = [],
) {
if (!empty($options['newDateTime'])) {
$this->rowNormalizer = fn($row, $resultSet) => Helpers::normalizeRow($row, $resultSet, DateTime::class);
}
if (empty($options['lazy'])) {
$this->connect();
}
Expand Down Expand Up @@ -113,6 +116,12 @@ public function getSupplementalDriver(): Driver
}


public function getReflection(): Reflection
{
return new Reflection($this->getDriver());
}


public function setRowNormalizer(?callable $normalizer): static
{
$this->rowNormalizer = $normalizer;
Expand Down
34 changes: 34 additions & 0 deletions site/vendor/nette/database/src/Database/DateTime.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/

declare(strict_types=1);

namespace Nette\Database;


/**
* Date Time.
*/
final class DateTime extends \DateTimeImmutable implements \JsonSerializable
{
/**
* Returns JSON representation in ISO 8601 (used by JavaScript).
*/
public function jsonSerialize(): string
{
return $this->format('c');
}


/**
* Returns the date and time in the format 'Y-m-d H:i:s.u'.
*/
public function __toString(): string
{
return $this->format('Y-m-d H:i:s.u');
}
}
20 changes: 5 additions & 15 deletions site/vendor/nette/database/src/Database/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,21 @@ function applyLimit(string &$sql, ?int $limit, ?int $offset): void;

/********************* reflection ****************d*g**/

/**
* Returns list of tables as tuples [(string) name, (bool) view, [(string) fullName]]
*/
/** @return list<array{name: string, fullName: string, view: bool}> */
function getTables(): array;

/**
* Returns metadata for all columns in a table.
* As tuples [(string) name, (string) table, (string) nativetype, (int) size, (bool) nullable, (mixed) default, (bool) autoincrement, (bool) primary, (array) vendor]]
*/
/** @return list<array{name: string, table: string, nativetype: string, size: int|null, nullable: bool, default: mixed, autoincrement: bool, primary: bool, vendor: array}> */
function getColumns(string $table): array;

/**
* Returns metadata for all indexes in a table.
* As tuples [(string) name, (string[]) columns, (bool) unique, (bool) primary]
*/
/** @return list<array{name: string, columns: list<string>, unique: bool, primary: bool}> */
function getIndexes(string $table): array;

/**
* Returns metadata for all foreign keys in a table.
* As tuples [(string) name, (string) local, (string) table, (string) foreign]
*/
/** @return list<array{name: string, local: string, table: string, foreign: string}> */
function getForeignKeys(string $table): array;

/**
* Returns associative array of detected types (IStructure::FIELD_*) in result set.
* @return array<string, string>
*/
function getColumnTypes(\PDOStatement $statement): array;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public function getColumnTypes(\PDOStatement $statement): array
for ($col = 0; $col < $count; $col++) {
$meta = $statement->getColumnMeta($col);
if (isset($meta['sqlite:decl_type'])) {
$types[$meta['name']] = in_array($meta['sqlite:decl_type'], ['DATE', 'DATETIME'], strict: true)
$types[$meta['name']] = $this->fmtDateTime === 'U' && in_array($meta['sqlite:decl_type'], ['DATE', 'DATETIME'], strict: true)
? Nette\Database\IStructure::FIELD_UNIX_TIMESTAMP
: Nette\Database\Helpers::detectType($meta['sqlite:decl_type']);
} elseif (isset($meta['native_type'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function getForeignKeys(string $table): array
fk.name AS name,
cl.name AS local,
tf.name AS [table],
cf.name AS [column]
cf.name AS [foreign]
FROM
sys.foreign_keys fk
JOIN sys.foreign_key_columns fkc ON fk.object_id = fkc.constraint_object_id
Expand Down
12 changes: 8 additions & 4 deletions site/vendor/nette/database/src/Database/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,11 @@ public static function detectType(string $type): string


/** @internal */
public static function normalizeRow(array $row, ResultSet $resultSet): array
public static function normalizeRow(
array $row,
ResultSet $resultSet,
$dateTimeClass = Nette\Utils\DateTime::class,
): array
{
foreach ($resultSet->getColumnTypes() as $key => $type) {
$value = $row[$key];
Expand All @@ -224,10 +228,10 @@ public static function normalizeRow(array $row, ResultSet $resultSet): array
} elseif ($type === IStructure::FIELD_DATETIME || $type === IStructure::FIELD_DATE) {
$row[$key] = str_starts_with($value, '0000-00')
? null
: new Nette\Utils\DateTime($value);
: new $dateTimeClass($value);

} elseif ($type === IStructure::FIELD_TIME) {
$row[$key] = (new Nette\Utils\DateTime($value))->setDate(1, 1, 1);
$row[$key] = (new $dateTimeClass($value))->setDate(1, 1, 1);

} elseif ($type === IStructure::FIELD_TIME_INTERVAL) {
preg_match('#^(-?)(\d+)\D(\d+)\D(\d+)(\.\d+)?$#D', $value, $m);
Expand All @@ -236,7 +240,7 @@ public static function normalizeRow(array $row, ResultSet $resultSet): array
$row[$key]->invert = (int) (bool) $m[1];

} elseif ($type === IStructure::FIELD_UNIX_TIMESTAMP) {
$row[$key] = Nette\Utils\DateTime::from($value);
$row[$key] = (new $dateTimeClass)->setTimestamp($value);
}
}

Expand Down
84 changes: 84 additions & 0 deletions site/vendor/nette/database/src/Database/Reflection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/

declare(strict_types=1);

namespace Nette\Database;

use Nette\Database\Reflection\Table;


final class Reflection
{
/** @var array<string, Table> */
public readonly array $tables;
private ?string $schema;


public function __construct(
private readonly Driver $driver,
) {
$this->schema = $this->driver->isSupported(Driver::SUPPORT_SCHEMA) ? 'public' : null;
unset($this->tables);
}


/** @return Table[] */
public function getTables(): array
{
return array_values($this->tables);
}


public function getTable(string $name): Table
{
$name = $this->getFullName($name);
return $this->tables[$name] ?? throw new \InvalidArgumentException("Table '$name' not found.");
}


public function hasTable(string $name): bool
{
$name = $this->getFullName($name);
return isset($this->tables[$name]);
}


private function getFullName(string $name): string
{
return $this->schema !== null && !str_contains($name, '.')
? $this->schema . '.' . $name
: $name;
}


/** @internal */
public function getDriver(): Driver
{
return $this->driver;
}


private function initTables(): void
{
$res = [];
foreach ($this->driver->getTables() as $row) {
$res[$row['fullName'] ?? $row['name']] = new Table($this, $row['name'], $row['view'], $row['fullName'] ?? null);
}
$this->tables = $res;
}


public function __get($name): mixed
{
match ($name) {
'tables' => $this->initTables(),
default => throw new \LogicException("Undefined property '$name'."),
};
return $this->$name;
}
}
37 changes: 37 additions & 0 deletions site/vendor/nette/database/src/Database/Reflection/Column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/

declare(strict_types=1);

namespace Nette\Database\Reflection;


/**
* Column reflection.
*/
final class Column
{
/** @internal */
public function __construct(
public readonly string $name,
public readonly ?Table $table = null,
public readonly string $nativeType = '',
public readonly ?int $size = null,
public readonly bool $nullable = false,
public readonly mixed $default = null,
public readonly bool $autoIncrement = false,
public readonly bool $primary = false,
public readonly array $vendor = [],
) {
}


public function __toString(): string
{
return $this->name;
}
}
Loading

0 comments on commit 8294231

Please sign in to comment.