modul-is / orm
Lightweight hybrid ORM/Explorer
Installs: 12 619
Dependents: 0
Suggesters: 0
Security: 0
Stars: 11
Watchers: 3
Forks: 0
Open Issues: 4
Language:HTML
Requires
- php: ^8.2
- nette/bootstrap: ^3.0
- nette/database: ^3.0 || ^4.0
- nette/utils: ^4.0
Requires (Dev)
- modul-is/coding-standard: ^4
- nette/caching: ^3.0
- nette/robot-loader: ^4.0
- nette/tester: ^2.5
- phpstan/phpstan: ^1
- tracy/tracy: ^2.7
This package is auto-updated.
Last update: 2024-11-09 15:56:38 UTC
README
Licence
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.
Abstract
This is a hybrid of a simple scalable database layer with ORM principles.
For usage and examples refer to quickstart.
Readonly
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;
Special types & behavior
- array - stored in database as json
- bool - stored in database as int
- \Nette\Utils\DateTime - save and load
\Nette\Utils\DateTime
Custom types
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'