Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/Resources/SnowflakeTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use DreamFactory\Core\Exceptions\BadRequestException;
use DreamFactory\Core\Exceptions\BatchException;
use DreamFactory\Core\SqlDb\Resources\Table;
use DreamFactory\Core\Database\Schema\TableSchema;
use Illuminate\Support\Collection;

use Arr;

class SnowflakeTable extends Table
Expand Down Expand Up @@ -84,6 +87,37 @@ public function createRecords($table, $records, $extras = [])

return $out;
}
/**
* @param TableSchema $schema
* @param Collection $result
* @return array
*/
public function decodeJsonField(TableSchema $schema, Collection $result): array {
$columns = $schema->getColumns();
$acceptedDbTypes = ["VARIANT"]; // Add your desired types here
$nvcharColumns = [];
foreach ($columns as $column) {
if (!in_array($column->dbType, $acceptedDbTypes)) continue;
$nvcharColumns[] = $column->name;
}
if (!empty($nvcharColumns)) {
$temp = $result->map(function ($item) use ($nvcharColumns) {
foreach ($nvcharColumns as $column) {
// json_decode wil return object if the decode is success or null
// in case of null => meaning the value is not valid json then we return the original value
$item[$column] = json_decode($item[$column]) ?? $item[$column];
}
return $item;
});
$result = collect($temp);
}

$data = $result->toArray();
if (!empty($meta)) {
$data['meta'] = $meta;
}
return $data;
}

/**
* {@inheritdoc}
Expand Down