hfw / db
基于注解的数据库CRUD
0.0.1
2021-07-26 13:51 UTC
Requires
- php: ~7.4
- ext-pdo: *
This package is auto-updated.
Last update: 2024-09-08 09:21:15 UTC
README
使用注解进行数据库存储和访问。
类注解
/**
* @record my_table
*/
class MyClass implements Helix\DB\EntityInterface, ArrayAccess {
use Helix\DB\AttributesTrait;
/**
* "id" is a required column.
* @column
* @var int
*/
protected $id = 0;
/**
* @column
* @var string
*/
protected $myColumn;
/**
* @eav foo_eav
* @var array
*/
protected $attributes;
/**
* @return int
*/
final public function getId() {
return $this->id;
}
}
- 列的名称必须与其对应的属性名称相同。
- EAV表必须包含3列:
entity
、attribute
和value
。entity
必须是外键。entity
和attribute
必须共同组成主键。
接口注解
接口可以注解为连接表。
/**
* @junction foo_bar
* @foreign foo_id Foo
* @foreign bar_id Bar
*/
interface FooBar { }
- 接口不需要实现。
- 引用的类可能相同。
支持驱动程序
- MySQL
- SQLite