jbschmitt/dbmodel

此包的最新版本(dev-main)没有提供许可证信息。

关系数据库的面向对象表示

安装: 0

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:

dev-main 2021-11-30 02:36 UTC

This package is auto-updated.

Last update: 2024-09-29 06:20:22 UTC


README

这是一个快速、轻量且简单的模型构建器,适用于您的关系数据库。它通过为您的MVC架构生成每个模型,减少了重复编写相同代码,同时不会降低速度。

需求

  • PHP 8.1(使用枚举类型)
    • 模块:PDO
  • mariadb/mysql数据库

安装/设置

每次更新数据库结构时,生成模型

composer require jbschmitt/dbmodel
composer exec dbmodel generate-all

它将要求您指定配置位置,并相对于该位置创建一个文件夹,用于包含所有“./Table/TablenameTable.php”和“./Base/TableNameBase.php”。

文档

每个表类都是静态的并实现

/**
 * array of primary key column(s)
 *
 * @return array
*/
public static function primaryKey():array

/**
 * columns of this table as an associative array
 *
 * @return array
 */
public static function columns():array

此外,每个基础模型类还提供

  • 每个列的获取器和设置器
  • update()insert()save()isNotNullValues()::where($array)方法

示例

存在一个名为“reservation”的表,具有以下列


$reservation = Reservation::where(['code' => "a1Hq"])->toModels()[0];
// where returns a Collection which can be converted to an array or the Model
$reservation->setActive(1);
$reservation->save(); 
// performs update, because it recognizes, that it already exists