Repository navigation
refactor(database): revise database column generation #2316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
aidan-casey
wants to merge
6
commits into
3.x
Choose a base branch
from
database-refactor
base: 3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,323
−1
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
022dbbb
initial columns testing
aidan-casey 50fdb9e
initial columns testing
aidan-casey f2f33a5
Adds compilers
aidan-casey 5f51b05
Revert inadvertant change.
aidan-casey 745a804
Adds table compilation
aidan-casey 7a6dc3b
Updates column objects for consistency.
aidan-casey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| ]); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| ]); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| ]); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| ]); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| ]); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| ]); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| ]); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| ]); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| ]); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rector. 😜