Skip to content

Commit a484643

Browse files
committed
feat(database): add string method on create table statement
1 parent 6451733 commit a484643

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

packages/database/src/QueryStatements/CreateTableStatement.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ public function varchar(string $name, int $length = 255, bool $nullable = false,
8383
return $this;
8484
}
8585

86+
public function string(string $name, int $length = 255, bool $nullable = false, ?string $default = null): self
87+
{
88+
return $this->varchar(
89+
name: $name,
90+
length: $length,
91+
nullable: $nullable,
92+
default: $default,
93+
);
94+
}
95+
8696
public function char(string $name, bool $nullable = false, ?string $default = null): self
8797
{
8898
$this->statements[] = new CharStatement(

tests/Integration/Database/QueryStatements/CreateTableStatementTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,43 @@ public function down(): ?QueryStatement
242242
$migration,
243243
);
244244
}
245+
246+
public function test_string_method_integration(): void
247+
{
248+
$migration = new class() implements DatabaseMigration {
249+
private(set) string $name = '0';
250+
251+
public function up(): QueryStatement
252+
{
253+
return new CreateTableStatement('frieren_table')
254+
->primary()
255+
->string('name', length: 100, nullable: false, default: 'Frieren')
256+
->string('type', nullable: true);
257+
}
258+
259+
public function down(): ?QueryStatement
260+
{
261+
return null;
262+
}
263+
};
264+
265+
$this->migrate(CreateMigrationsTable::class, $migration);
266+
267+
$this->expectNotToPerformAssertions();
268+
}
269+
270+
public function test_string_method_with_custom_parameters(): void
271+
{
272+
$varcharStatement = new CreateTableStatement('frieren_mages')
273+
->primary()
274+
->varchar('name', length: 120, nullable: true, default: 'Himmel')
275+
->compile(DatabaseDialect::MYSQL);
276+
277+
$stringStatement = new CreateTableStatement('frieren_mages')
278+
->primary()
279+
->varchar('name', length: 120, nullable: true, default: 'Himmel')
280+
->compile(DatabaseDialect::MYSQL);
281+
282+
$this->assertSame($varcharStatement, $stringStatement);
283+
}
245284
}

0 commit comments

Comments
 (0)