Пример #1
0
 /**
  * @inheritdoc
  */
 public function checkColumn(Column $column)
 {
     if ($column->flags & Column::TIMESTAMP) {
         if (!$column->getDefault()) {
             $column->setFlag(Column::NOT_NULL);
             $column->setDefault(new Raw('CURRENT_TIMESTAMP'));
         }
     }
 }
Пример #2
0
 /**
  * Required setup column types in provided columns object
  * @param $columns static|\stdClass
  */
 static function setUpColumns($columns)
 {
     $columns->id = Column::AUTO_ID;
     $columns->tagIds = Column::create(Column::STRING + Column::NOT_NULL)->setDefault('')->setUnique();
     $columns->projectId = Column::cast(Project::columns()->id)->copy()->setFlag(Column::NOT_NULL, false);
     $columns->lastSeen = Column::INTEGER + Column::TIMESTAMP;
 }
Пример #3
0
 /**
  * Required setup column types in provided columns object
  * @param $columns static|\stdClass
  */
 static function setUpColumns($columns)
 {
     $columns->id = Column::AUTO_ID;
     $columns->apiKey = Column::STRING;
     $columns->name = Column::create(Column::STRING)->setUnique();
     $columns->description = Column::STRING;
 }
Пример #4
0
 /**
  * Required setup column types in provided columns object
  * @param $columns static|\stdClass
  */
 static function setUpColumns($columns)
 {
     $columns->id = Column::AUTO_ID;
     $columns->suiteId = Suite::columns()->id;
     $columns->sessionId = Session::columns()->id;
     $columns->hostId = Host::columns()->id;
     $columns->tagIds = Column::create(Column::STRING + Column::NOT_NULL)->setIndexed();
 }
Пример #5
0
 static function setUpColumns($columns)
 {
     $columns->wallTime = Column::create(Column::INTEGER + Column::NOT_NULL);
     $columns->calls = Column::create(Column::INTEGER + Column::NOT_NULL);
     $columns->memoryUsage = Column::create(Column::INTEGER + Column::NOT_NULL);
     $columns->peakMemoryUsage = Column::create(Column::INTEGER + Column::NOT_NULL);
     $columns->cpu = Column::create(Column::INTEGER + Column::NOT_NULL);
     $columns->runs = Column::create(Column::INTEGER + Column::NOT_NULL);
 }
Пример #6
0
 static function setUpColumns($columns)
 {
     $columns->id = Column::create(Column::AUTO_ID);
     $columns->id->schemaName = '_id';
     $columns->routeId = Column::INTEGER;
     $columns->starred = Column::INTEGER;
     $columns->description = Column::STRING;
     $columns->name = Column::STRING;
 }
Пример #7
0
 static function setUpColumns($columns)
 {
     $columns->id = Column::AUTO_ID;
     $columns->latestStatId = Stat7Days::columns()->id;
     $columns->userName = Column::create(Column::STRING)->setUnique();
     $columns->wakaId = Column::create(Column::STRING)->setUnique();
     $columns->avatarUrl = Column::STRING;
     $columns->fullName = Column::STRING;
     $columns->joined = Column::INTEGER;
 }
Пример #8
0
 static function setUpColumns($columns)
 {
     $columns->id = Column::AUTO_ID;
     $columns->albumId = Column::cast(Album::columns()->id)->copy()->setFlag(Column::NOT_NULL, false);
     $columns->height = Column::INTEGER + Column::SIZE_2B + Column::NOT_NULL;
     $columns->width = Column::INTEGER + Column::SIZE_2B + Column::NOT_NULL;
     $columns->path = Column::STRING + Column::NOT_NULL;
     $columns->url = Column::STRING + Column::NOT_NULL;
     $columns->hash = Column::create(Column::STRING)->setStringLength(32, true)->setUnique();
 }
Пример #9
0
 static function setUpColumns($columns)
 {
     $columns->id = Column::AUTO_ID;
     $columns->ut = Column::TIMESTAMP + Column::INTEGER;
     $columns->runs = Column::create(Column::INTEGER + Column::NOT_NULL)->setDefault(0);
     $columns->name = Column::STRING;
     $columns->projectId = Column::cast(Project::columns()->id)->copy()->setFlag(Column::NOT_NULL, false);
     $columns->tagGroupId = Column::cast(TagGroup::columns()->id)->copy()->setFlag(Column::NOT_NULL, false);
     parent::setUpColumns($columns);
 }
Пример #10
0
 public function getTableDefinition($tableName)
 {
     $tableSymbol = new Symbol($tableName);
     $res = $this->database->query("DESC ?", $tableSymbol);
     $columns = new \stdClass();
     while ($row = $res->fetchRow()) {
         $type = $row['Type'];
         $field = $row['Field'];
         $phpType = $this->getTypeByString($type);
         if ('auto_increment' === $row['Extra']) {
             $phpType += Column::AUTO_ID;
         }
         $column = new Column($phpType);
         $columns->{$field} = $column;
         $column->schemaName = $field;
         $notNull = $row['Null'] === 'NO';
         if ($row['Default'] !== null || !$notNull) {
             $column->setDefault($row['Default']);
         }
         $column->setFlag(Column::NOT_NULL, $notNull);
     }
     $definition = new Table($columns, $this->database, $tableName);
     $res = $this->database->query("SHOW INDEX FROM ?", $tableSymbol);
     $indexes = array();
     $uniqueIndex = array();
     foreach ($res as $row) {
         $indexes[$row['Key_name']][$row['Seq_in_index']] = $columns->{$row['Column_name']};
         $uniqueIndex[$row['Key_name']] = !$row['Non_unique'];
     }
     foreach ($indexes as $indexName => $indexData) {
         ksort($indexData);
         $index = new Index(array_values($indexData));
         $index->setName($indexName);
         $index->setType($uniqueIndex[$indexName] ? Index::TYPE_UNIQUE : Index::TYPE_KEY);
         if ($indexName === self::_PRIMARY) {
             $definition->setPrimaryKey($index->columns);
         } else {
             $definition->addIndex($index);
         }
     }
     return $definition;
 }
Пример #11
0
 /**
  * @return Table|static
  */
 public static function entityDefinition()
 {
     /** @var static $columns */
     $columns = new \stdClass();
     $columns->id = new Column(Column::AUTO_ID + Column::INTEGER);
     // TODO auto primary
     $columns->url = Column::create(Column::STRING);
     // TODO unique
     $def = new Table($columns);
     return $def;
 }
Пример #12
0
 static function setUpColumns($columns)
 {
     $columns->id = Column::create(Column::INTEGER + Column::AUTO_ID + Column::NOT_NULL + Column::UNSIGNED);
     $columns->wakaUserId = WakaUser::columns()->id;
     $columns->branch = Column::create(Column::STRING);
     $columns->duration = Column::create(Column::FLOAT + Column::NOT_NULL);
     $columns->entity = Column::create(Column::STRING);
     $columns->language = Column::create(Column::STRING);
     $columns->project = Column::create(Column::STRING);
     $columns->time = Column::create(Column::INTEGER);
     $columns->type = Column::create(Column::STRING);
 }
Пример #13
0
 private function parseColumn(Parser $parser)
 {
     $columnName = $parser->inner(null, array(' ', "\r", "\n", "\t"));
     $columnName = (string) $this->resolve(trim($columnName));
     $type = (string) $parser->inner(null, ' ');
     $unsigned = $parser->contain('UNSIGNED', true);
     $notNull = $parser->contain('NOT NULL', true);
     $autoId = $this->isAutoId($parser);
     $default = $parser->inner('DEFAULT ', null, false, true);
     if (!$default->isEmpty()) {
         $default = (string) $default;
         $defUpper = strtoupper($default);
         if ('NULL' === $defUpper) {
             $default = null;
         } elseif ('CURRENT_TIMESTAMP' === $defUpper) {
             $default = new Raw($defUpper);
         } elseif (strpos($default, self::BIND_PREFIX) !== false) {
             $default = $this->resolve($default);
         }
     } else {
         $default = false;
     }
     $flags = $this->getTypeByString($type);
     if ($notNull) {
         $flags += Column::NOT_NULL;
     }
     if ($autoId) {
         $flags += Column::AUTO_ID;
     }
     if ($unsigned) {
         $flags += Column::UNSIGNED;
     }
     $column = new Column($flags);
     if ($length = (string) $parser->setOffset(0)->inner('VARCHAR(', ')', false, true)) {
         $column->setStringLength($length, false);
     } elseif ($length = (string) $parser->setOffset(0)->inner('CHAR(', ')', false, true)) {
         $column->setStringLength($length, true);
     }
     $column->setDefault($default);
     $column->schemaName = $columnName;
     $this->columns->{$columnName} = $column;
 }
Пример #14
0
 public function getColumns($tableName)
 {
     //echo PHP_EOL . 'table: ' . $tableName . PHP_EOL;
     $res = $this->database->select()->select('c.column_name, c.is_nullable, c.data_type, c.column_default, tc.constraint_type')->from('INFORMATION_SCHEMA.COLUMNS AS c')->leftJoin('INFORMATION_SCHEMA.constraint_column_usage AS ccu ON c.column_name = ccu.column_name AND c.table_name = ccu.table_name')->leftJoin('INFORMATION_SCHEMA.table_constraints AS tc ON ccu.constraint_name = tc.constraint_name')->where('c.table_name = ?', $tableName)->order('c.ordinal_position ASC')->query();
     $columns = new \stdClass();
     while ($r = $res->fetchRow()) {
         //print_r($r);
         $field = $r['column_name'];
         //echo 'field: ' . $field . PHP_EOL;
         $phpType = $this->getColumnFlagsByString($r['data_type']);
         $notNull = $r['is_nullable'] === 'NO';
         $column = new Column($phpType);
         $skipDefault = false;
         if ('nextval' === substr($r['column_default'], 0, 7)) {
             $column->setFlag(Column::AUTO_ID);
             $column->setFlag(Column::INTEGER);
             $skipDefault = true;
         }
         $column->setFlag(Column::NOT_NULL, $notNull);
         if (!$skipDefault) {
             $default = $r['column_default'];
             if ($default !== null || !$notNull) {
                 if (is_string($default)) {
                     if ("'" === $default[0]) {
                         $pos = strrpos($default, "'::");
                         if ($pos !== false) {
                             $default = substr($default, 1, $pos - 1);
                         }
                     } elseif ('NULL::' === substr($default, 0, 6)) {
                         $default = null;
                     }
                 }
                 $column->setDefault($default);
             }
         }
         $columns->{$field} = $column;
     }
     return $columns;
 }
Пример #15
0
 public function toArray($skipNotSetProperties = false, $skipCast = false)
 {
     $result = array();
     foreach (static::table()->getColumns(true) as $column) {
         $value = $this->{$column->propertyName};
         if ($value instanceof Undefined) {
             if ($skipNotSetProperties) {
                 continue;
             } else {
                 $value = $column->getDefault();
             }
         } elseif (!$skipCast) {
             $value = Column::castField($value, $column->flags, false);
         }
         $result[$column->schemaName] = $value;
     }
     return $result;
 }
Пример #16
0
 static function setUpColumns($columns)
 {
     $columns->identityId = Identity::columns()->id;
     $columns->token = Column::create(Column::STRING + Column::NOT_NULL)->setStringLength(32, true)->setUnique();
     $columns->createdAt = Column::INTEGER;
 }
Пример #17
0
 static function setUpTable(\Yaoi\Database\Definition\Table $table, $columns)
 {
     $table->setSchemaName('TrackElement');
     Column::cast($columns->id)->schemaName = '_id';
     Column::cast($columns->trackId)->schemaName = 'trackId';
 }
Пример #18
0
 /**
  * Setup column types in provided columns object
  * @param $columns static|\stdClass
  */
 static function setUpColumns($columns)
 {
     $columns->id = Column::AUTO_ID;
     $columns->name = Column::create(Column::STRING)->setUnique();
 }