table = $table; } public function data(string $col, mixed $val): InsertionBuilder { if (!isset($this->table->columns[$col])) throw new InvalidArgumentException("Column '$col' does not exist."); $columnType = $this->table->columns[$col]['colType']; $this->currentRow[$col] = $columnType->valCast($val); return $this; } public function done(): InsertionBuilder { if (!empty($this->currentRow)) { $this->batchRows[] = $this->currentRow; $this->currentRow = []; } $this->isReady = true; return $this; } public function insert(): void { global $wpdb; // Convert single to batch queries. if (!$this->isReady and !empty($this->currentRow)) { $this->batchRows[] = $this->currentRow; $this->currentRow = []; $this->isReady = true; } if (empty($this->batchRows)) throw new InvalidArgumentException("No data set for insertion."); foreach ($this->batchRows as $row) if (!empty($row)) $wpdb->insert($this->table->tableName, $row); } }