tp6混合easyswoole DLL 多应用模式 修改版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
4.2 KiB

5 years ago
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: mayn
  5. * Date: 2019/9/4
  6. * Time: 23:46
  7. */
  8. namespace EasySwoole\DDL\Test;
  9. require_once 'vendor/autoload.php';
  10. use EasySwoole\DDL\Blueprint\Table;
  11. use EasySwoole\DDL\DDLBuilder;
  12. use EasySwoole\DDL\Enum\Character;
  13. use EasySwoole\DDL\Enum\Engine;
  14. $stuQql = DDLBuilder::table('student', function (Table $table) {
  15. $table->setIfNotExists()->setTableComment('学生表'); //设置表名称/
  16. $table->setTableCharset(Character::UTF8MB4_GENERAL_CI);//设置表字符集
  17. $table->colInt('stu_id')->setIsAutoIncrement()->setIsPrimaryKey()->setIsUnsigned()->setColumnComment('学生ID'); //创建stu_id设置主键并自动增长
  18. $table->colVarChar('stu_name', 30)->setColumnComment('学生姓名');
  19. $table->colChar('sex', 1)->setColumnComment('性别:1男,2女')->setDefaultValue(1);
  20. $table->colDate('birthday')->setIsNotNull(false)->setColumnComment('出生日期');
  21. $table->colInt('created_at', 10)->setColumnComment('创建时间');
  22. $table->colInt('updated_at', 10)->setColumnComment('更新时间');
  23. $table->indexNormal('stu_name_index', 'stu_name')->setIndexComment('学生姓名--普通索引');//设置索引
  24. });
  25. echo $stuQql . "\r\n";
  26. $courseSql = DDLBuilder::table('course', function (Table $table) {
  27. $table->setIfNotExists()->setTableComment('课程表'); //设置表名称/
  28. $table->setTableCharset(Character::UTF8MB4_GENERAL_CI);//设置表字符集
  29. $table->colInt('id', 3)->setIsPrimaryKey()->setIsAutoIncrement()->setIsUnsigned()->setZeroFill()->setColumnComment('课程id');
  30. $table->colVarChar('course_name', 100)->setColumnComment('课程名称');
  31. $table->colChar('status', 1)->setDefaultValue(1)->setColumnComment('课程状态:1正常,0隐藏');
  32. $table->colInt('created_at', 10)->setColumnComment('创建时间');
  33. $table->colInt('updated_at', 10)->setColumnComment('更新时间');
  34. $table->indexUnique('course_name_index', 'course_name')->setIndexComment('课程名称--唯一索引');//设置索引
  35. });
  36. echo $courseSql . "\r\n";
  37. $scoreSql = DDLBuilder::table('score', function (Table $table) {
  38. $table->setIfNotExists()->setTableComment('成绩表'); //设置表名称/
  39. $table->setTableCharset(Character::UTF8MB4_GENERAL_CI);//设置表字符集
  40. $table->colInt('id')->setIsUnsigned()->setIsAutoIncrement()->setIsPrimaryKey()->setColumnComment('自增ID');
  41. $table->colInt('stu_id')->setIsUnsigned()->setColumnComment('学生id');
  42. $table->colInt('course_id')->setIsUnsigned()->setZeroFill()->setColumnComment('课程id');
  43. $table->colFloat('score', 3, 1)->setColumnComment('成绩');
  44. $table->colInt('created_at', 10)->setColumnComment('创建时间');
  45. });
  46. echo $scoreSql;
  47. //以下是输出sql语句
  48. /*
  49. CREATE TABLE IF NOT EXISTS `student` (
  50. `stu_id` int UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '学生ID',
  51. `stu_name` varchar(30) NOT NULL COMMENT '学生姓名',
  52. `sex` char(1) NOT NULL DEFAULT 1 COMMENT '性别:1男,2女',
  53. `birthday` date NOT NULL COMMENT '出生日期',
  54. `created_at` int(10) NOT NULL COMMENT '创建时间',
  55. `updated_at` int(10) NOT NULL COMMENT '更新时间',
  56. INDEX `stu_name_index` (`stu_name`) COMMENT '学生姓名--普通索引'
  57. )
  58. ENGINE = INNODB DEFAULT COLLATE = 'utf8mb4_general_ci' COMMENT = '学生表';
  59. CREATE TABLE IF NOT EXISTS `course` (
  60. `id` int(3) UNSIGNED ZEROFILL NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '课程id',
  61. `course_name` varchar(100) NOT NULL COMMENT '课程名称',
  62. `status` char(1) NOT NULL DEFAULT 1 COMMENT '课程状态:1正常,0隐藏',
  63. `created_at` int(10) NOT NULL COMMENT '创建时间',
  64. `updated_at` int(10) NOT NULL COMMENT '更新时间',
  65. UNIQUE INDEX `course_name_index` (`course_name`) COMMENT '课程名称--唯一索引'
  66. )
  67. ENGINE = INNODB DEFAULT COLLATE = 'utf8mb4_general_ci' COMMENT = '课程表';
  68. CREATE TABLE IF NOT EXISTS `score` (
  69. `id` int UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '自增ID',
  70. `stu_id` int UNSIGNED NOT NULL COMMENT '学生id',
  71. `course_id` int UNSIGNED ZEROFILL NOT NULL COMMENT '课程id',
  72. `score` float(3,1) NOT NULL COMMENT '成绩',
  73. `created_at` int(10) NOT NULL COMMENT '创建时间'
  74. )
  75. ENGINE = INNODB DEFAULT COLLATE = 'utf8mb4_general_ci' COMMENT = '成绩表';
  76. */