web-base/core/Driver/SQL/Query/Insert.class.php

48 lines
1.2 KiB
PHP
Raw Normal View History

2020-04-02 00:02:51 +02:00
<?php
namespace Driver\SQL\Query;
2020-04-03 17:39:58 +02:00
use Driver\SQL\Strategy\Strategy;
2020-04-02 00:02:51 +02:00
class Insert extends Query {
2020-04-03 17:39:58 +02:00
private string $tableName;
private array $columns;
private array $rows;
private ?Strategy $onDuplicateKey;
private ?string $returning;
2020-04-02 00:02:51 +02:00
public function __construct($sql, $name, $columns=array()) {
parent::__construct($sql);
$this->tableName = $name;
$this->columns = $columns;
$this->rows = array();
$this->onDuplicateKey = NULL;
2020-04-02 01:48:46 +02:00
$this->returning = NULL;
2020-04-02 00:02:51 +02:00
}
public function addRow(...$values) {
$this->rows[] = $values;
return $this;
}
public function onDuplicateKeyStrategy($strategy) {
$this->onDuplicateKey = $strategy;
return $this;
}
2020-04-02 01:48:46 +02:00
public function returning($column) {
$this->returning = $column;
return $this;
}
2020-04-02 00:02:51 +02:00
public function execute() {
return $this->sql->executeInsert($this);
}
public function getTableName() { return $this->tableName; }
public function getColumns() { return $this->columns; }
public function getRows() { return $this->rows; }
public function onDuplicateKey() { return $this->onDuplicateKey; }
2020-04-02 01:48:46 +02:00
public function getReturning() { return $this->returning; }
2020-04-03 17:39:58 +02:00
}