CastsModel.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace EasySwoole\ORM\Tests\models;
  3. use EasySwoole\DDL\Blueprint\Table;
  4. use EasySwoole\Mysqli\QueryBuilder;
  5. use EasySwoole\ORM\AbstractModel;
  6. use EasySwoole\ORM\DbManager;
  7. class CastsModel extends AbstractModel
  8. {
  9. protected $tableName = 'casts';
  10. protected $autoTimeStamp = false;
  11. protected $casts = [
  12. 'int_value' => 'int',
  13. 'float_value' => 'float',
  14. 'json_value' => 'json',
  15. 'array_value' => 'array',
  16. 'date_value' => 'date',
  17. 'datetime_value' => 'datetime',
  18. 'timestamp_value' => 'timestamp'
  19. ];
  20. public function __construct(array $data = [])
  21. {
  22. $table = new Table('casts');
  23. $table->setIfNotExists();
  24. $table->int('id')->setIsPrimaryKey(true)->setIsAutoIncrement(true);
  25. $table->int('int_value', 11);
  26. $table->float('float_value', 10, 2);
  27. $table->char('json_value', 100);
  28. $table->char('array_value', 100);
  29. $table->date('date_value');
  30. $table->datetime('datetime_value');
  31. $table->int('timestamp_value', 11);
  32. $builder = new QueryBuilder();
  33. $builder->raw($table->__toString());
  34. DbManager::getInstance()->query($builder);
  35. parent::__construct($data);
  36. }
  37. }