-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #5
- Loading branch information
Showing
5 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,38 @@ | ||
<?php | ||
namespace Gt\SqlBuilder\Query; | ||
|
||
class DeleteQuery extends SqlQuery { | ||
public function __toString():string { | ||
$query = $this->processClauseList([ | ||
self::PRE_QUERY_COMMENT => $this->preQuery(), | ||
"delete from" => $this->from(), | ||
"partition" => $this->partition(), | ||
"where" => $this->where(), | ||
"order by" => $this->orderBy(), | ||
"limit" => $this->limit(), | ||
self::POST_QUERY_COMMENT => $this->postQuery(), | ||
]); | ||
|
||
return $query; | ||
} | ||
|
||
public function from():array { | ||
return []; | ||
} | ||
|
||
public function partition():array { | ||
return []; | ||
} | ||
|
||
public function where():array { | ||
return []; | ||
} | ||
|
||
public function orderBy():array { | ||
return []; | ||
} | ||
|
||
public function limit():array { | ||
return []; | ||
} | ||
} |
This file contains 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,24 @@ | ||
<?php | ||
namespace Gt\SqlBuilder\Test\Helper; | ||
|
||
use Gt\SqlBuilder\Query\DeleteQuery; | ||
|
||
class DeleteOrderByExample extends DeleteQuery { | ||
public function from():array { | ||
return [ | ||
"student", | ||
]; | ||
} | ||
|
||
public function orderBy():array { | ||
return [ | ||
"createdAt desc" | ||
]; | ||
} | ||
|
||
public function limit():array { | ||
return [ | ||
10, | ||
]; | ||
} | ||
} |
This file contains 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,22 @@ | ||
<?php | ||
namespace Gt\SqlBuilder\Test\Helper\Query; | ||
|
||
use Gt\SqlBuilder\Query\DeleteQuery; | ||
|
||
class DeleteExample extends DeleteQuery { | ||
public function from():array { | ||
return [ | ||
"student", | ||
]; | ||
} | ||
|
||
public function where():array { | ||
return [ | ||
"id = :id", | ||
]; | ||
} | ||
|
||
public function limit():array { | ||
return [1]; | ||
} | ||
} |
This file contains 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,26 @@ | ||
<?php | ||
namespace Gt\SqlBuilder\Test\Helper\Query; | ||
|
||
use Gt\SqlBuilder\Query\DeleteQuery; | ||
|
||
class DeletePartitionExample extends DeleteQuery { | ||
public function from():array { | ||
return [ | ||
"student", | ||
]; | ||
} | ||
|
||
public function partition():array { | ||
return [ | ||
"exp1", | ||
"exp2", | ||
"exp3", | ||
]; | ||
} | ||
|
||
public function where():array { | ||
return [ | ||
"toDelete = 1", | ||
]; | ||
} | ||
} |
This file contains 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,27 @@ | ||
<?php | ||
namespace Gt\SqlBuilder\Test\Query; | ||
|
||
use Gt\SqlBuilder\Test\Helper\DeleteOrderByExample; | ||
use Gt\SqlBuilder\Test\Helper\Query\DeleteExample; | ||
use Gt\SqlBuilder\Test\Helper\Query\DeletePartitionExample; | ||
use Gt\SqlBuilder\Test\QueryTestCase; | ||
|
||
class DeleteQueryTest extends QueryTestCase { | ||
public function testDelete() { | ||
$sut = new DeleteExample(); | ||
$sql = self::normalise($sut); | ||
self::assertEquals("delete from student where id = :id limit 1", $sql); | ||
} | ||
|
||
public function testDeletePartition() { | ||
$sut = new DeletePartitionExample(); | ||
$sql = self::normalise($sut); | ||
self::assertEquals("delete from student partition ( exp1, exp2, exp3 ) where toDelete = 1", $sql); | ||
} | ||
|
||
public function testDeleteOrderBy() { | ||
$sut = new DeleteOrderByExample(); | ||
$sql = self::normalise($sut); | ||
self::assertEquals("delete from student order by createdAt desc limit 10", $sql); | ||
} | ||
} |