日韩在线观看-日韩在线成人-日韩在线不卡视频-日韩在线不卡视频-国产精品99-国产精品99

模型創建腳本

注冊腳本命令

ORM 提供了創建模型的命令,您可以很方便的根據數據表創建對應模型。不過這個功能目前僅限在 EasySwoole 框架中使用。

php easyswoole.php model gen -table={table_name}

在使用腳本之前需要先在 EasySwoole 框架中進行注冊 ORM 連接池和注冊創建腳本命令,修改 EasySwoole 框架根目錄的 bootstrap.php 文件,如下:

<?php
// bootstrap.php
// 全局bootstrap事件
date_default_timezone_set('Asia/Shanghai');

$argvArr = $argv;
array_shift($argvArr);
$command = $argvArr[0] ?? null;
if ($command === 'model') {
    \EasySwoole\EasySwoole\Core::getInstance()->initialize();
}
\EasySwoole\Command\CommandManager::getInstance()->addCommand(new \EasySwoole\FastDb\Commands\ModelCommand());

創建模型

可選參數如下:

參數 類型 默認值 備注
-db-connection string default 連接池名稱,腳本會根據當前連接池配置創建
-path string App/Model 模型路徑
-with-comments bool false 是否增加字段屬性注釋

創建示例

在數據庫中先導入數據表 DDL,如:

CREATE TABLE `easyswoole_user`
(
    `id`      int unsigned NOT NULL AUTO_INCREMENT COMMENT 'increment id',
    `name`    varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'name',
    `status`  tinyint unsigned DEFAULT '0' COMMENT 'status',
    `score`   int unsigned DEFAULT '0' COMMENT 'score',
    `sex`     tinyint unsigned DEFAULT '0' COMMENT 'sex',
    `address` json                                                          DEFAULT NULL COMMENT 'address',
    `email`   varchar(150) COLLATE utf8mb4_general_ci                       DEFAULT NULL COMMENT 'email',
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

或數據庫已有上述數據表也可。

執行如下命令,創建模型:

php easyswoole.php model gen -table=easyswoole_user -with-comments

創建的模型如下:

<?php

declare(strict_types=1);

namespace App\Model;

use EasySwoole\FastDb\AbstractInterface\AbstractEntity;
use EasySwoole\FastDb\Attributes\Property;

/**
 * @property int $id
 * @property string|null $name
 * @property int|null $status
 * @property int|null $score
 * @property int|null $sex
 * @property string|null $address
 * @property string|null $email
 */
class EasyswooleUser extends AbstractEntity
{
    #[Property(isPrimaryKey: true)]
    public int $id;
    #[Property]
    public ?string $name;
    #[Property]
    public ?int $status;
    #[Property]
    public ?int $score;
    #[Property]
    public ?int $sex;
    #[Property]
    public ?string $address;
    #[Property]
    public ?string $email;

    public function tableName(): string
    {
        return 'easyswoole_user';
    }
}
主站蜘蛛池模板: 红色诗配画| 林熙蕾三级| 艾娜| 监禁逃亡2| 雪中悍刀行第一季电视剧免费观看 | leslie| 丰崎爱生| 红髅| 大众故事1974意大利| 香谱七十二法图大全| 忘忧草电影| 成毅壁纸| 贾林| 变形金刚6免费完整版在线观看| 张大民的幸福生活| 欧美xxxx做受性欧美蜜臀av| 叶玉卿电影| angels of death| 安全员c证考试免费题库| 91精品在线视频播放| 晕车喝什么饮料能缓解| 卢靖姗老公是谁| 潜伏电视剧全集30集免费观看| 好好歌词| 伤残等级1-10标准图| 无常电影| 77316电影| 男女的隐私视频播放| kaya| 浙江卫视网络直播源| 李姝| 林芳| 宁死不屈电影免费观看| 妻子的秘密按摩电影| 抖音网页版入| 澳亚卫视| 崔在焕| xiee| 猎兽神兵免费全集在线观看高清版| 电车男| 《欢乐谷》电影|