hfw/db

Database CRUD by annotation

0.0.1 2021-07-26 13:51 UTC

This package is auto-updated.

Last update: 2024-12-08 10:01:06 UTC


README

Database storage and access using annotations.

Documentation: https://hfw.github.io/db

Class Annotations

/**
 * @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;
    }

}
    
  • Columns must be named the same as their respective properties.
  • EAV tables must have 3 columns: entity, attribute, and value.
    • entity must be a foreign key.
    • entity and attribute must form the primary key.

Interface Annotations

Interfaces can be annotated to act as junctions.

/**
 * @junction foo_bar
 * @foreign foo_id Foo
 * @foreign bar_id Bar
 */
interface FooBar { }
  • The interfaces don't have to be implemented.
  • The referenced classes may be identical.

Supported Drivers

  • MySQL
  • SQLite

Class Diagram