gsferro / database-schema-easy
Simple and efficient way to manipulate your database connection scheme, whatever it may be.
Requires
- php: ^8.0
- doctrine/orm: 2.14|3.*
- laravel/framework: 8.*|9.*|10.*
README
Simple and efficient way to manipulate your database connection scheme, whatever it may be.
Instalação:
composer require gsferro/database-schema-easy
Dependências:
Uso:
-
Instancie o serviço
$schema = new DatabaseSchemaEasy(string $table, string $connection = null);
-
Facade
$schema = dbschemaeasy(string $table)
Métodos:
-
hasTable(): bool
: Verifica se a table exists$schema->hasTable(); # true
-
getColumnListing(bool $includePrimaryKeys = true, bool $includeTimestamps = false): array
: Retorna todas as colunas da table$schema->getColumnListing(); /* [ "id", "uuid", "pedido_status_id", ] */
-
hasColumn(string $column): bool
: Verifica se a coluna exists$schema->hasColumn('id'); # true
-
hasColumns(array $columns): bool
:Verifica se as colunas exists$schema->hasColumns(['id', 'uuid']); # true
-
hasColumnsTimestamps(): bool
: Verifica se a coluna exists$schema->hasColumnsTimestamps(); # true
-
getTypeFromColumns(array $columns): array
: Pega todos os tipos das colunas$schema->getTypeFromColumns(['id', 'uuid']); /* [ "id" => "integer", "uuid" => "guid", ] */
-
getColumnType(string $column): string
:Retorna o type da colunas$schema->getColumnType('id'); # "integer"
-
getDoctrineColumn(string $column): array
:Retorna todas as informações da colunas$schema->getDoctrineColumn('id'); /* [ "name" => "id", "type" => Doctrine\DBAL\Types\IntegerType {#4751}, "default" => null, "notnull" => true, "length" => null, "precision" => 10, "scale" => 0, "fixed" => false, "unsigned" => false, "autoincrement" => true, "columnDefinition" => null, "comment" => null, "primary_key" => true, ] */
-
isPrimaryKey(string $column): bool
:Verifica se a coluna é pk$schema->isPrimaryKey('id'); # true
-
primaryKeys(): array
:Retorna as chaves pks$schema->primaryKeys(); /* [ "id", ] */
-
hasModelWithTableName(string $table = null): bool|string
:Verifica se a table já existe model eloquent criada$schema->hasModelWithTableName(); # "App\Models\Pedidos" $schema->hasModelWithTableName('abc'); # false
-
getAllTables(): array
: Todas as tabelas da conexão$schema->getAllTables(); /* [ 'pedidos', 'pedido_status, ... ] */
-
hasForeinsKey(string $column, bool $fromStubReplace = false): bool|array
: Verifica se a coluna é uma foreing key e devolve os dados do relacionamento$schema->hasForeinsKey('pedido_status_id'); /* [ "table" => "pedido_status", "tableCamel" => Illuminate\Support\Stringable {#5069 value: "pedidoStatus", }, "related" => Illuminate\Support\Stringable {#5068 value: "", }, "relatedInstance" => false, "foreignKey" => "pedido_status_id", "ownerKey" => "id", ] */