Lightweight hybrid ORM/Explorer

Installs: 12 619

Dependents: 0

Suggesters: 0

Security: 0

Stars: 11

Watchers: 3

Forks: 0

Open Issues: 4

Language:HTML

v2.2.2 2024-11-06 11:44 UTC

README

badge-version badge-licence badge-stars badge-issues

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:

  1. input(string $name, $value) - save logic (conversion into a database-compatible type)
  2. 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'