-
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.
Merge pull request #12 from PhpGt/select
Basic functionality and tests
- Loading branch information
Showing
33 changed files
with
805 additions
and
22 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,36 @@ | ||
<?php | ||
namespace Gt\SqlBuilder\Query; | ||
|
||
class DeleteQuery extends SqlQuery { | ||
public function __toString():string { | ||
return $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(), | ||
]); | ||
} | ||
|
||
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,31 @@ | ||
<?php | ||
namespace Gt\SqlBuilder\Query; | ||
|
||
class InsertQuery extends ReplaceQuery { | ||
public function __toString():string { | ||
$query = $this->processClauseList([ | ||
self::PRE_QUERY_COMMENT => $this->preQuery(), | ||
"insert into" => $this->into(), | ||
"partition" => $this->partition(), | ||
"set" => $this->normaliseSet($this->set()), | ||
"on duplicate key update" => $this->normaliseSet($this->onDuplicate()), | ||
self::POST_QUERY_COMMENT => $this->postQuery(), | ||
]); | ||
|
||
if($this->subQuery) { | ||
$query = "( $query )"; | ||
} | ||
|
||
return $query; | ||
} | ||
|
||
/** | ||
* Return an assignment list that matches the set() rules. It is often | ||
* useful to return a call to set() directly, as it is usual to list the | ||
* same assignments as part of the "on duplicate key update" section as | ||
* in the "set" section. | ||
*/ | ||
public function onDuplicate():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,52 @@ | ||
<?php | ||
namespace Gt\SqlBuilder\Query; | ||
|
||
class ReplaceQuery extends SqlQuery { | ||
public function __toString():string { | ||
$query = $this->processClauseList([ | ||
self::PRE_QUERY_COMMENT => $this->preQuery(), | ||
"replace into" => $this->into(), | ||
"partition" => $this->partition(), | ||
"set" => $this->normaliseSet($this->set()), | ||
self::POST_QUERY_COMMENT => $this->postQuery(), | ||
]); | ||
|
||
if($this->subQuery) { | ||
$query = "( $query )"; | ||
} | ||
|
||
return $query; | ||
} | ||
|
||
public function into():array { | ||
return []; | ||
} | ||
|
||
public function partition():array { | ||
return []; | ||
} | ||
|
||
/** | ||
* Return either an associative array where the keys are the column | ||
* names and the values are the assignment values, or an indexed array | ||
* where the values are the column names where the values will be | ||
* inferred as the column name prefixed with the colon character. | ||
*/ | ||
public function set():array { | ||
return []; | ||
} | ||
|
||
protected function normaliseSet(array $setData):array { | ||
$normalised = []; | ||
foreach($setData as $i => $name) { | ||
if(is_int($i)) { | ||
$normalised[$name] = ":$name"; | ||
} | ||
else { | ||
$normalised[$i] = $name; | ||
} | ||
} | ||
|
||
return $normalised; | ||
} | ||
} |
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
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
Oops, something went wrong.