From 43880eb428874348dce3fbe0c6853a56b0af9bda Mon Sep 17 00:00:00 2001 From: Dave M Date: Thu, 23 Mar 2023 15:09:42 +0000 Subject: [PATCH] - Migrated Entity's file into attributes --- src/Entity/InformationSchema/Column.php | 97 ++++++---------------- src/Entity/InformationSchema/Table.php | 105 +++++++----------------- src/Entity/Sqlite/Column.php | 35 +++----- src/Entity/Sqlite/Schema.php | 31 +++---- 4 files changed, 77 insertions(+), 191 deletions(-) diff --git a/src/Entity/InformationSchema/Column.php b/src/Entity/InformationSchema/Column.php index 829c26f..a291663 100644 --- a/src/Entity/InformationSchema/Column.php +++ b/src/Entity/InformationSchema/Column.php @@ -4,121 +4,78 @@ namespace Ulmus\Entity\InformationSchema; use Ulmus\Entity\Field\Datetime; -/** - * @Table('name' => "columns", 'database' => "information_schema") - */ +use Ulmus\{Attribute\Obj\Table}; +use Ulmus\Attribute\Property\{Field, Filter, FilterJoin, Relation, Join, Virtual, Where}; + +#[Table(name: "columns", database: "information_schema")] class Column { use \Ulmus\EntityTrait; - /** - * @Field('name' => "TABLE_CATALOG", 'length' => 512) - */ + #[Field(name: "TABLE_CATALOG", length: 512)] public string $tableCatalog; - /** - * @Field('name' => "TABLE_SCHEMA", 'length' => 64) - */ + #[Field(name: "TABLE_SCHEMA", length: 64)] public string $tableSchema; - /** - * @Field('name' => "TABLE_NAME", 'length' => 64) - */ + #[Field(name: "TABLE_NAME", length: 64)] public string $tableName; - /** - * @Field('name' => "COLUMN_NAME", 'length' => 64, 'attributes' => [ 'primary_key' => true ]) - */ + #[Field(name: "COLUMN_NAME", length: 64, attributes: [ 'unsigned' => true, ])] public string $name; - /** - * @Field('name' => "ORDINAL_POSITION", 'type' => "bigint", 'length' => 21, 'attributes' => [ 'unsigned' => true ]) - */ + #[Field(name: "ORDINAL_POSITION", type: "bigint", length: 21, attributes: [ 'unsigned' => true, ])] public int $ordinalPosition; - /** - * @Field('name' => "COLUMN_DEFAULT", 'type' => "longtext") - */ + #[Field(name: "COLUMN_DEFAULT", type: "longtext")] public ? string $default; - /** - * @Field('name' => "IS_NULLABLE", 'length' => 3) - */ + #[Field(name: "IS_NULLABLE", length: 3)] public string $nullable; - /** - * @Field('name' => "DATA_TYPE", 'length' => 64) - */ + #[Field(name: "DATA_TYPE", length: 64)] public string $dataType; - /** - * @Field('name' => "CHARACTER_MAXIMUM_LENGTH", 'type' => "bigint", 'length' => 21, 'attributes' => [ 'unsigned' => true ]) - */ + #[Field(name: "CHARACTER_MAXIMUM_LENGTH", type: "bigint", length: 21, attributes: [ 'unsigned' => true, ])] public ? int $characterMaximumLength; - /** - * @Field('name' => "CHARACTER_OCTET_LENGTH", 'type' => "bigint", 'length' => 21, 'attributes' => [ 'unsigned' => true ]) - */ + #[Field(name: "CHARACTER_OCTET_LENGTH", type: "bigint", length: 21, attributes: [ 'unsigned' => true, ])] public ? int $characterOctetLength; - /** - * @Field('name' => "NUMERIC_PRECISION", 'type' => "bigint", 'length' => 21, 'attributes' => [ 'unsigned' => true ]) - */ + #[Field(name: "NUMERIC_PRECISION", type: "bigint", length: 21, attributes: [ 'unsigned' => true, ])] public ? int $numericPrecision; - /** - * @Field('name' => "NUMERIC_SCALE", 'type' => "bigint", 'length' => 21, 'attributes' => [ 'unsigned' => true ]) - */ + #[Field(name: "NUMERIC_SCALE", type: "bigint", length: 21, attributes: [ 'unsigned' => true, ])] public ? int $numericScale; - /** - * @Field('name' => "DATETIME_PRECISION", 'type' => "bigint", 'length' => 21, 'attributes' => [ 'unsigned' => true ]) - */ + #[Field(name: "DATETIME_PRECISION", type: "bigint", length: 21, attributes: [ 'unsigned' => true, ])] public ? int $datetimePrecision; - /** - * @Field('name' => "CHARACTER_SET_NAME", 'length' => 32) - */ + #[Field(name: "CHARACTER_SET_NAME", length: 32)] public ? string $characterSetName; - /** - * @Field('name' => "COLLATION_NAME", 'length' => 32) - */ + #[Field(name: "COLLATION_NAME", length: 32)] public ? string $collationName; - /** - * @Field('name' => "COLLATION_TYPE", 'type' => "longtext") - */ - public string $type; +# #[Field(name: "COLLATION_TYPE", type: "longtext")] +# public string $type; - /** - * @Field('name' => "COLUMN_KEY", 'length' => 3) - */ + #[Field(name: "COLUMN_KEY", length: 3)] public string $key; - /** - * @Field('name' => "EXTRA", 'length' => 30) - */ + #[Field(name: "EXTRA", length: 30)] public string $extra; - /** - * @Field('name' => "PRIVILEGES", 'length' => 80) - */ + #[Field(name: "PRIVILEGES", length: 80)] public string $privileges; - /** - * @Field('name' => "COLUMN_COMMENT", 'length' => 1024) - */ + #[Field(name: "COLUMN_COMMENT", length: 1024)] public string $comment; - /** - * @Field('name' => "IS_GENERATED", 'length' => 6) - */ + #[Field(name: "IS_GENERATED", length: 6)] public string $generated; - /** - * @Field('name' => "GENERATION_EXPRESSION", 'type' => "longtext") - */ + #[Field(name: "GENERATION_EXPRESSION", type: "longtext")] public ? string $generationExpression; } \ No newline at end of file diff --git a/src/Entity/InformationSchema/Table.php b/src/Entity/InformationSchema/Table.php index 958dd51..384837a 100644 --- a/src/Entity/InformationSchema/Table.php +++ b/src/Entity/InformationSchema/Table.php @@ -5,131 +5,84 @@ namespace Ulmus\Entity\InformationSchema; use Ulmus\EntityCollection, Ulmus\Entity\Field\Datetime; -/** - * @Table('name' => "tables", 'database' => "information_schema") - */ +use Ulmus\{Attribute\Obj\Table as TableObj}; +use Ulmus\Attribute\Property\{Field, Filter, FilterJoin, Relation, Join, Virtual, Where}; + +#[TableObj(name: "tables", database: "information_schema")] class Table { use \Ulmus\EntityTrait; - /** - * @Field('name' => "TABLE_CATALOG", 'length' => 512) - */ + #[Field(name: "TABLE_CATALOG", length: 512)] public string $catalog; - /** - * @Field('name' => "TABLE_SCHEMA", 'length' => 64) - */ + #[Field(name: "TABLE_SCHEMA", length: 64)] public string $schema; - /** - * @Field('name' => "TABLE_NAME", 'length' => 64, 'attributes' => [ 'primary_key' => true ]) - */ + #[Field(name: "TABLE_NAME", length: 64, attributes: [ 'primary_key' => true, ])] public string $name; - /** - * @Field('name' => "TABLE_TYPE", 'length' => 64) - */ + #[Field(name: "TABLE_TYPE", length: 64)] public string $type; - /** - * @Field('name' => "ENGINE", 'length' => 64) - */ + #[Field(name: "ENGINE", length: 64)] public ? string $engine ; - /** - * @Field('name' => "VERSION", 'type' => "bigint", 'length' => 21, 'attributes' => [ 'unsigned' => true ]) - */ + #[Field(name: "VERSION", type: "bigint", length: 21, attributes: [ 'unsigned' => true, ])] public ? string $version; - /** - * @Field('name' => "ROW_FORMAT", 'length' => 10) - */ + #[Field(name: "ROW_FORMAT", length: 10)] public ? string $rowFormat; - /** - * @Field('name' => "TABLE_ROWS", 'type' => "bigint", 'length' => 21, 'attributes' => [ 'unsigned' => true ]) - */ + #[Field(name: "TABLE_ROWS", type: "bigint", length: 21, attributes: [ 'unsigned' => true, ])] public ? string $rows; - /** - * @Field('name' => "AVG_ROW_LENGTH", 'type' => "bigint", 'length' => 21, 'attributes' => [ 'unsigned' => true ]) - */ + #[Field(name: "AVG_ROW_LENGTH", type: "bigint", length: 21, attributes: [ 'unsigned' => true, ])] public ? string $averageRowLength; - /** - * @Field('name' => "DATA_LENGTH", 'type' => "bigint", 'length' => 21, 'attributes' => [ 'unsigned' => true ]) - */ + #[Field(name: "DATA_LENGTH", type: "bigint", length: 21, attributes: [ 'unsigned' => true, ])] public ? string $dataLength; - /** - * @Field('name' => "MAX_DATA_LENGTH", 'type' => "bigint", 'length' => 21, 'attributes' => [ 'unsigned' => true ]) - */ + #[Field(name: "MAX_DATA_LENGTH", type: "bigint", length: 21, attributes: [ 'unsigned' => true, ])] public ? string $maxDataLength; - /** - * @Field('name' => "INDEX_LENGTH", 'type' => "bigint", 'length' => 21, 'attributes' => [ 'unsigned' => true ]) - */ + #[Field(name: "INDEX_LENGTH", type: "bigint", length: 21, attributes: [ 'unsigned' => true, ])] public ? string $indexLength; - /** - * @Field('name' => "DATA_FREE", 'type' => "bigint", 'length' => 21, 'attributes' => [ 'unsigned' => true ]) - */ + #[Field(name: "DATA_FREE", type: "bigint", length: 21, attributes: [ 'unsigned' => true, ])] public ? string $dataFree; - /** - * @Field('name' => "AUTO_INCREMENT", 'type' => "bigint", 'length' => 21, 'attributes' => [ 'unsigned' => true ]) - */ + #[Field(name: "AUTO_INCREMENT", type: "bigint", length: 21, attributes: [ 'unsigned' => true, ])] public ? string $autoIncrement; - /** - * @Field('name' => "CREATE_TIME") - */ + #[Field(name: "CREATE_TIME")] public ? Datetime $createTime; - /** - * @Field('name' => "UPDATE_TIME") - */ + #[Field(name: "UPDATE_TIME")] public ? Datetime $updateTime; - /** - * @Field('name' => "CHECK_TIME") - */ + #[Field(name: "CHECK_TIME")] public ? Datetime $checkTime; - /** - * @Field('name' => "TABLE_COLLATION", 'length' => 32) - */ + #[Field(name: "TABLE_COLLATION", length: 32)] public ? string $tableCollation; - /** - * @Field('name' => "CHECKSUM", 'type' => "bigint", 'length' => 21, 'attributes' => [ 'unsigned' => true ]) - */ + #[Field(name: "CHECKSUM", type: "bigint", length: 21, attributes: [ 'unsigned' => true, ])] public ? string $checksum; - /** - * @Field('name' => "CREATE_OPTIONS", 'length' => 2048) - */ + #[Field(name: "CREATE_OPTIONS", length: 2048)] public ? string $createOptions; - /** - * @Field('name' => "TABLE_COMMENT", 'length' => 2048) - */ + #[Field(name: "TABLE_COMMENT", length: 2048)] public string $tableComment; - /** - * @Field('name' => "MAX_INDEX_LENGTH", 'type' => "bigint", 'length' => 21, 'attributes' => [ 'unsigned' => true ]) - */ + #[Field(name: "MAX_INDEX_LENGTH", type: "bigint", length: 21, attributes: [ 'unsigned' => true, ])] public ? int $maxIndexLength; - /** - * @Field('name' => "TEMPORARY", 'length' => 1) - */ + #[Field(name: "TEMPORARY", length: 1)] public ? string $temporary; - /** - * @Relation('oneToMany', 'key' => 'name', 'foreignKey' => Column::field('tableName'), 'entity' => Column::class) - * @Where('TABLE_SCHEMA', Column::field('tableSchema')) - */ + #[Relation(type: "oneToMany", key: "name", foreignKey: [ Column::class, 'tableName' ], entity: Column::class)] + #[Where('TABLE_SCHEMA', [ Column::class, 'tableSchema' ])] public EntityCollection $columns; } \ No newline at end of file diff --git a/src/Entity/Sqlite/Column.php b/src/Entity/Sqlite/Column.php index c36d0f1..bb420b2 100644 --- a/src/Entity/Sqlite/Column.php +++ b/src/Entity/Sqlite/Column.php @@ -4,45 +4,32 @@ namespace Ulmus\Entity\Sqlite; use Ulmus\EntityCollection; -/** - * @Table - */ +use Ulmus\{Attribute\Obj\Table}; +use Ulmus\Attribute\Property\{Field, Filter, FilterJoin, Relation, Join, Virtual, Where}; + +#[Table] class Column { use \Ulmus\EntityTrait; - /** - * @Id - */ + #[Id] public int $cid; - /** - * @Field - */ + #[Field] public string $type; - /** - * @Field - */ + #[Field] public string $name; - /** - * @Virtual - */ + #[Virtual] public string $tableName; - /** - * @Field('name' => "notnull") - */ + #[Field(name: "notnull")] public bool $notNull; - /** - * @Field('name' => 'dflt_value') - */ + #[Field(name: "dflt_value")] public ? string $defaultValue; - /** - * @Field('name' => "pk") - */ + #[Field(name: "pk")] public bool $primaryKey; } \ No newline at end of file diff --git a/src/Entity/Sqlite/Schema.php b/src/Entity/Sqlite/Schema.php index ed57e5f..f15aae8 100644 --- a/src/Entity/Sqlite/Schema.php +++ b/src/Entity/Sqlite/Schema.php @@ -4,40 +4,29 @@ namespace Ulmus\Entity\Sqlite; use Ulmus\EntityCollection; -/** - * @Table('name' => "sqlite_master") - */ +use Ulmus\{Attribute\Obj\Table}; +use Ulmus\Attribute\Property\{Field, Filter, FilterJoin, Relation, Join, Virtual, Where}; + +#[Table(name: "sqlite_master")] class Schema { use \Ulmus\EntityTrait; - /** - * @Id - */ + #[Id] public ? string $name; - /** - * @Field - */ + #[Field] public ? string $type; - /** - * @Field('name' => 'tbl_name') - */ + #[Field(name: "tbl_name")] public ? string $tableName; - /** - * @Field - */ + #[Field] public ? int $rootpage; - /** - * @Field - */ + #[Field] public ? string $sql; - /** - * @Relation('oneToMany', 'key' => 'tableName', 'foreignKey' => 'tableName', 'entity' => Schema::class) - */ + #[Relation("oneToMany", key: "tableName", foreignKey: "tableName", entity: "Schema")] public EntityCollection $columns; } \ No newline at end of file