在线看片18_亚洲性吧_在线污_神马午夜达达兔_奇米色网_在线免费看污

模型創建腳本

注冊腳本命令

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';
    }
}
主站蜘蛛池模板: 男人午夜视频 | 色综合一区二区 | 欧美亚洲视频在线观看 | 三上悠亚 在线观看 | 午夜免费av | 国产色图视频 | 久久久久久久91 | h色网站在线观看 | 色婷婷视频在线 | 久艹伊人 | 亚洲欧美国产精品专区久久 | 日本成人福利视频 | 风间由美在线视频 | 99视频+国产日韩欧美 | 久久久国产一区二区 | 日韩精品在线观看视频 | 黄色三级av | 亚洲另类色图 | 亚洲热在线 | 亚洲国产视频在线 | 国产欧美精品一区二区三区 | 大色网小色网 | www五月天com | 欧美一级爆毛片 | 亚洲女人18毛片水真多 | 中文字幕高清在线观看 | 欧美高清一区二区 | 久草欧美 | 咪咪色影院 | 在线观看国产黄色 | 91视频久久久 | 可以免费在线观看的av | 欧美日本一区二区三区 | 日韩专区在线观看 | 欧美视频第一页 | 一级片免费观看 | 人人超碰97 | 天天操天天操 | 91视频免费观看网站 | 欧美日韩在线观看一区 | 黑人巨大精品欧美 |