hfw/db

基于注解的数据库CRUD

0.0.1 2021-07-26 13:51 UTC

This package is auto-updated.

Last update: 2024-09-08 09:21:15 UTC


README

使用注解进行数据库存储和访问。

文档:https://hfw.github.io/db

类注解

/**
 * @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列:entityattributevalue
    • entity必须是外键。
    • entityattribute必须共同组成主键。

接口注解

接口可以注解为连接表。

/**
 * @junction foo_bar
 * @foreign foo_id Foo
 * @foreign bar_id Bar
 */
interface FooBar { }
  • 接口不需要实现。
  • 引用的类可能相同。

支持驱动程序

  • MySQL
  • SQLite

类图