Add JSON type support in object property handling

- Added `json` to the list of valid types for object properties.
- Implemented JSON decoding for column values when the type is `json`.
This commit is contained in:
Jeppe Bundgaard
2025-11-05 13:16:31 +01:00
parent 0180523539
commit f206e7f4fb
@@ -51,7 +51,7 @@ class object_property
throw new \InvalidArgumentException("Table or column cannot be empty");
}
// Check if the type is valid
if (!in_array($this->type, ['int', 'varchar', 'text', 'date', 'datetime', 'string', 'timestamp', 'boolean', 'bool', 'float'])) {
if (!in_array($this->type, ['int', 'varchar', 'text', 'date', 'datetime', 'string', 'timestamp', 'boolean', 'bool', 'float', 'json'])) {
throw new \InvalidArgumentException("Invalid type: $this->type");
}
$sql = "SELECT $this->column FROM $this->table WHERE id = $this->id";
@@ -60,6 +60,11 @@ class object_property
if (empty($row)) {
throw new \RuntimeException("No record found for column '$this->column' in table '$this->table' with ID $this->id");
}
// If the type is set to json, decode it.
$value = $row[$this->column];
if ($this->type === 'json' && $value !== null) {
return json_decode($value, true);
}
return $row[$this->column];
}