Skip to content

Commit

Permalink
Merge pull request #6 from Infamoustrey/chunking-row-inserts
Browse files Browse the repository at this point in the history
Chunking row inserts
  • Loading branch information
Trey Foster authored Nov 2, 2021
2 parents ee752d0 + 90b8ecc commit b49907a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/Resources/Sheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public function dropAndReplace(array $rows)
{
$this->dropAllRows();

$this->addRows($rows);
foreach (collect($rows)->chunk(500) as $chunk) {
$this->addRows($chunk->toArray());
}
}

public function dropAllRows()
Expand Down Expand Up @@ -186,6 +188,7 @@ public function addRows(array $rows): object
'cells' => $this->generateRowCells($cells)
];
})
->values()
->toArray()
);
}
Expand Down Expand Up @@ -272,10 +275,10 @@ public function replaceRows(array $cells, string $primaryColumnName)
* Adds a row to the sheet
*
* @param array $cells
* @return array
* @return object
* @throws Exception
*/
public function createRow(array $cells): array
public function createRow(array $cells): object
{
return $this->insertRows([
'toBottom' => true,
Expand Down
2 changes: 1 addition & 1 deletion src/SmartsheetClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function getFolder(string $folderId): Folder
*/
public function getWorkspace(string $workspaceId): Workspace
{
return new Workspace($this, $this->get("workspaces/$workspaceId"));
return new Workspace($this, (array) $this->get("workspaces/$workspaceId"));
}

/**
Expand Down

0 comments on commit b49907a

Please sign in to comment.