This repository is an overhaul of YetORM under MIT licence. Original fork kravcik/core will not be maintained for Nette3. You can find the unfinished PR for YetORM and Nette 3 here.
This is a hybrid of a simple scalable database layer with ORM principles.
For usage and examples refer to quickstart.
The ReadonlyProperty attribute can be used for properties that should not be written into, for example columns with auto increment.
#[\ModulIS\Attribute\ReadonlyProperty]
public int $id;
- array - stored in database as json
- bool - stored in database as int
- \Nette\Utils\DateTime - save and load
\Nette\Utils\DateTime
Input | Entity | Nullable | Output |
---|---|---|---|
int(1) | int | ✓ || ✗ | int(1) |
int(0) | int | ✓ || ✗ | int(0) |
string("0") | int | ✓ || ✗ | Exception |
float(1.0) | float | ✓ || ✗ | float(1.0) |
float(0.0) | float | ✓ || ✗ | float(0.0) |
string("0.0") | float | ✓ || ✗ | Exception |
string("a") | string | ✓ || ✗ | string("a") |
string("") | string | ✓ || ✗ | string("") |
array(["a" => "b"]) | array | ✓ || ✗ | string("{"a":"b"}") |
array([]) | array | ✓ || ✗ | string("[]") |
string("{"a":"b"}") | array | ✓ || ✗ | Exception |
string("[]") | array | ✓ || ✗ | Exception |
bool(false) | bool | ✓ || ✗ | bool(false) |
string("false") | bool | ✓ || ✗ | Exception |
DateTime("2021-01-01 12:34:56") | DateTime | ✓ || ✗ | string("2021-01-01 12:34:56") |
string("2021-01-01 12:34:56") | DateTime | ✓ || ✗ | Exception |
int(0) | float || string || array || bool || DateTime | ✓ || ✗ | Exception |
float(0.0) | int || string || array || bool || DateTime | ✓ || ✗ | Exception |
string("") | int || float || array || bool || DateTime | ✓ || ✗ | Exception |
array([]) | int || float || string || bool || DateTime | ✓ || ✗ | Exception |
bool(false) | int || float || string || array || DateTime | ✓ || ✗ | Exception |
null | int || float || string || array || bool || DateTime | ✓ | null |
null | int || float || string || array || bool || DateTime | ✗ | Exception |
You can also use custom types, you just have to create a class that extends \ModulIS\Datatype\Datatype
and implements both of its static functions:
input(string $name, $value)
- save logic (conversion into a database-compatible type)output($value)
- read logic (conversion back into the original type)
class File extends \ModulIS\Datatype\Datatype
{
public static function input(string $name, $value): string
{
if($value instanceof \SplFileInfo)
{
$value = $value->getPathname();
}
else
{
throw new \ModulIS\Exception\InvalidArgumentException("Invalid type for column '{$name}' - Instance of '\SplFileInfo' expected, '" . get_debug_type($value) . "' given.");
}
return $value;
}
public static function output($value): self
{
$value = new self(new \SplFileInfo($value));
return $value;
}
}
Then you can use your type with a property just like all the usual types.
public \App\Datatype\File $file;
Just make sure the data is always wrapped in the specified class to avoid errors.
$entity->file = new \App\Datatype\File(new \SplFileInfo('../app/Datatype/File.php'));
bdump($entity->file); //App\Datatype\File(value: SplFileInfo(path: '../app/Datatype/File.php'));
bdump($entity->file->value->getFilename()); //'File.php'