openwebx / feijaovermelho
基于RedBeanPHP的ORM
1.0
2020-11-09 04:52 UTC
Requires
- php: >=7.4
- ext-igbinary: *
- ext-json: *
- cocur/slugify: ^4.0
- gabordemooij/redbean: ^5.6
- openwebx/opencache: ^1.0
- openwebx/opentraits: dev-main
- openwebx/strings: dev-main
- phpfastcache/phpfastcache: ^8.0
- vlucas/phpdotenv: ^5.1
- webmozart/assert: ^1.9
Requires (Dev)
- rector/rector: ^0.8.47
README
基于RedBeanPHP的ORM
命名
“feijão vermelho”在葡萄牙语中简单意味着“红豆”。
想法
由于我在大约一打项目中使用了RedBeanPHP,我真的很喜欢将对象放入数据库、读取它们、更改它们的简单易用性。只要你的对象从底层开始设计以使用RedBean,就没有问题。
我想通过这个小库实现的是在项目的大多数类/对象中透明地使用RedBeanPHP...
安装
composer require openwebx/feijaovermelho
用法
用于简单的操作,如将对象保存到数据库、从数据库中获取对象或“upserting”(更新或插入),操作非常直接
将对象保存到数据库
<?php use openWebX\feijaoVermelho\feijaoVermelho class Test { // use our trait... use feijaoVermelho; // define some public properties public int $intValue; public string $stringValue; } // now simply let feijaoVermelho do its magic: $myTest = new Test(); $myTest->intValue = 666; $myTest->stringValue = 'this is a test'; $myTest->save();
当数据库可访问且配置正确时(见配置...),将有一个名为“test”的表,其中至少有一条记录,包含id、int_value和string_value字段...
从数据库加载对象
现在让我们从数据库中获取我们的对象
<?php [...] $myNewObject = new Test(); $myNewObject->intValue = 666; $myNewObject->loadByIntValue(); echo $myNewObject->stringValue; // -> this is a test