Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/Exceptions/ExceptionTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private function findRecordedProcessings(string|object $exception): array
return true;
}

return class_exists($exception) && is_a($reported, $exception, allow_string: true);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rector. 😜

return class_exists($exception) && $reported instanceof $exception;
});
}

Expand Down
19 changes: 19 additions & 0 deletions packages/database/src/Columns/CharColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Tempest\Database\Columns;

use Tempest\Database\Columns\Concerns\IsColumn;

final class CharColumn implements Column
{
use IsColumn;

private(set) int $length = 1;

public function length(int $length): self
{
return clone($this, [
'length' => $length,
]);
}
}
18 changes: 18 additions & 0 deletions packages/database/src/Columns/Column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Tempest\Database\Columns;

interface Column
{
public string $name { get; }
public bool $nullable { get; }
public mixed $default { get; }
public bool $unique { get; }
public bool $primaryKey { get; }

public function name(string $name): static;

public function nullable(bool $nullable = true): static;

public function default(mixed $default): static;
}
53 changes: 53 additions & 0 deletions packages/database/src/Columns/Concerns/IsColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Tempest\Database\Columns\Concerns;

trait IsColumn
{
private(set) bool $primaryKey = false;

private(set) bool $nullable = false;

private(set) mixed $default;

private(set) bool $unique = false;

public function __construct(
private(set) string $name,
) {}

public function name(string $name): static
{
return clone($this, [
'name' => $name,
]);
}

public function primaryKey(): static
{
return clone($this, [
'primaryKey' => true,
]);
}

public function nullable(bool $nullable = true): static
{
return clone($this, [
'nullable' => $nullable,
]);
}

public function default(mixed $default): static
{
return clone($this, [
'default' => $default,
]);
}

public function unique(bool $unique = true): self
{
return clone($this, [
'unique' => $unique,
]);
}
}
19 changes: 19 additions & 0 deletions packages/database/src/Columns/DateColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Tempest\Database\Columns;

use Tempest\Database\Columns\Concerns\IsColumn;

final class DateColumn implements Column
{
use IsColumn;

private(set) bool $current = false;

public function useCurrent(): self
{
return clone($this, [
'current' => true,
]);
}
}
42 changes: 42 additions & 0 deletions packages/database/src/Columns/DateTimeColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Tempest\Database\Columns;

use InvalidArgumentException;
use Tempest\Database\Columns\Concerns\IsColumn;

final class DateTimeColumn implements Column
{
use IsColumn;

private(set) int $precision = 0;
private(set) bool $current = false;
private(set) bool $currentOnUpdate = false;

public function precision(int $precision): self
{
if ($precision < 0 || $precision > 6) {
throw new InvalidArgumentException(
'Precision must be between 0 and 6.',
);
}

return clone($this, [
'precision' => $precision,
]);
}

public function current(): self
{
return clone($this, [
'current' => true,
]);
}

public function currentOnUpdate(): self
{
return clone($this, [
'currentOnUpdate' => true,
]);
}
}
19 changes: 19 additions & 0 deletions packages/database/src/Columns/FloatColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Tempest\Database\Columns;

use Tempest\Database\Columns\Concerns\IsColumn;

final class FloatColumn implements Column
{
use IsColumn;

private(set) bool $unsigned = false;

public function unsigned(): self
{
return clone($this, [
'unsigned' => true,
]);
}
}
28 changes: 28 additions & 0 deletions packages/database/src/Columns/IntegerColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Tempest\Database\Columns;

use Tempest\Database\Columns\Concerns\IsColumn;

final class IntegerColumn implements Column
{
use IsColumn;

private(set) bool $autoIncrement = false;

private(set) bool $unsigned = false;

public function autoIncrement(bool $autoIncrement = true): self
{
return clone($this, [
'autoIncrement' => $autoIncrement,
]);
}

public function unsigned(bool $unsigned = true): self
{
return clone($this, [
'unsigned' => $unsigned,
]);
}
}
19 changes: 19 additions & 0 deletions packages/database/src/Columns/TextColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Tempest\Database\Columns;

use Tempest\Database\Columns\Concerns\IsColumn;

final class TextColumn implements Column
{
use IsColumn;

private(set) int $length = 65_535;

public function length(int $length): self
{
return clone($this, [
'length' => $length,
]);
}
}
19 changes: 19 additions & 0 deletions packages/database/src/Columns/UuidColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Tempest\Database\Columns;

use Tempest\Database\Columns\Concerns\IsColumn;

final class UuidColumn implements Column
{
use IsColumn;

private(set) bool $generated = false;

public function generated(): self
{
return clone($this, [
'generated' => true,
]);
}
}
19 changes: 19 additions & 0 deletions packages/database/src/Columns/VarcharColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Tempest\Database\Columns;

use Tempest\Database\Columns\Concerns\IsColumn;

final class VarcharColumn implements Column
{
use IsColumn;

private(set) int $length = 255;

public function length(int $length): self
{
return clone($this, [
'length' => $length,
]);
}
}
10 changes: 10 additions & 0 deletions packages/database/src/Compilers/ColumnCompiler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Tempest\Database\Compilers;

use Tempest\Database\Columns\Column;

interface ColumnCompiler
{
public function compile(Column $column): string;
}
Loading
Loading