-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
133 additions
and
33 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
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
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 Packaged\QueryBuilder\Builder\Traits; | ||
|
||
use Packaged\QueryBuilder\Clause\InsertClause; | ||
use Packaged\QueryBuilder\Clause\ValuesClause; | ||
use Packaged\QueryBuilder\Expression\FieldExpression; | ||
use Packaged\QueryBuilder\Expression\ValueExpression; | ||
use Packaged\QueryBuilder\Statement\IStatement; | ||
|
||
trait InsertTrait | ||
{ | ||
public function insert($table, ...$fields) | ||
{ | ||
|
||
/** | ||
* @var $this IStatement | ||
*/ | ||
$clause = new InsertClause(); | ||
$this->addClause($clause); | ||
$clause->setTable($table); | ||
|
||
foreach($fields as $field) | ||
{ | ||
if(!($field instanceof FieldExpression)) | ||
{ | ||
$field = FieldExpression::create($field); | ||
} | ||
$clause->addField($field); | ||
} | ||
return $this; | ||
} | ||
|
||
public function values(...$values) | ||
{ | ||
/** | ||
* @var $this IStatement | ||
* @var $clause ValuesClause | ||
*/ | ||
$clause = new ValuesClause(); | ||
$this->addClause($clause); | ||
|
||
foreach($values as $value) | ||
{ | ||
if(!($value instanceof ValueExpression)) | ||
{ | ||
$value = ValueExpression::create($value); | ||
} | ||
$clause->addExpression($value); | ||
} | ||
return $this; | ||
} | ||
} |
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
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