定制 modul-is/orm 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

modul-is/orm

Composer 安装命令:

composer require modul-is/orm

包简介

Lightweight hybrid ORM/Explorer

README 文档

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
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

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'

统计信息

  • 总下载量: 19.01k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 2
  • Forks: 0
  • 开发语言: HTML

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-12-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固