gsferro / database-schema-easy
简单高效地操作您的数据库连接方案,无论其是什么。
v1.1.1
2023-05-04 16:03 UTC
Requires
- php: ^8.0
- doctrine/orm: 2.14|3.*
- laravel/framework: 8.*|9.*|10.*
README
简单高效地操作您的数据库连接方案,无论其是什么。
安装
composer require gsferro/database-schema-easy
依赖关系
使用
-
实例化服务
$schema = new DatabaseSchemaEasy(string $table, string $connection = null);
-
外观
$schema = dbschemaeasy(string $table)
方法
-
hasTable(): bool
: 检查表是否存在$schema->hasTable(); # true
-
getColumnListing(bool $includePrimaryKeys = true, bool $includeTimestamps = false): array
: 返回表的全部列$schema->getColumnListing(); /* [ "id", "uuid", "pedido_status_id", ] */
-
hasColumn(string $column): bool
: 检查列是否存在$schema->hasColumn('id'); # true
-
hasColumns(array $columns): bool
: 检查列是否存在$schema->hasColumns(['id', 'uuid']); # true
-
hasColumnsTimestamps(): bool
: 检查列是否存在$schema->hasColumnsTimestamps(); # true
-
getTypeFromColumns(array $columns): array
: 获取所有列的类型$schema->getTypeFromColumns(['id', 'uuid']); /* [ "id" => "integer", "uuid" => "guid", ] */
-
getColumnType(string $column): string
: 返回列的类型$schema->getColumnType('id'); # "integer"
-
getDoctrineColumn(string $column): array
: 返回列的全部信息$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
: 检查列是否为主键$schema->isPrimaryKey('id'); # true
-
primaryKeys(): array
: 返回主键$schema->primaryKeys(); /* [ "id", ] */
-
hasModelWithTableName(string $table = null): bool|string
: 检查是否存在已创建的Eloquent模型$schema->hasModelWithTableName(); # "App\Models\Pedidos" $schema->hasModelWithTableName('abc'); # false
-
getAllTables(): array
: 连接中的所有表$schema->getAllTables(); /* [ 'pedidos', 'pedido_status, ... ] */
-
hasForeinsKey(string $column, bool $fromStubReplace = false): bool|array
: 检查列是否为外键并返回关联数据$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", ] */