shadetheartist/schema-info

使用简单的流畅API分析和导航数据库结构

1.6.0 2017-04-08 01:42 UTC

This package is not auto-updated.

Last update: 2024-09-23 16:42:01 UTC


README

一个实用类,旨在以高效的方式帮助接口与数据库模式信息交互。

设置

首先,将schema-info依赖项添加到项目的composer文件中

composer.json

"require": {
    ...,
    "shadetheartist/schema-info": "1.5.3"
}

在您的终端运行composer dump-autoload

其次,通过以下方式将SchemaInfo服务提供者和外观添加到项目的引导程序中

config/app.php

'providers' => [
    ...,
    SchemaInfo\SchemaInfoServiceProvider::class,
]

这样设置就完成了!

示例

一般用法

创建新的模式实例

<?php namespace App;

use SchemaInfo\Facades\SchemaInfo;

class Example
{
    public function example()
    {
        $schema = SchemaInfo::make();
    }
   
    public function exampleAltConnection()
    {
    	//connect to a different database. note: only mysql databases are currently supported.
        $schema = SchemaInfo::make(\DB::connection('my-alternative-connection'));
    }
}

表格使用

$table = $schema->table('my_table_name');

//returns a stdClass instance refecting a record from the schema info of your database.
$info = $table->info();

检索列

$table = $schema->table('my_table_name');

$column = $table->column('my_column_name');

$allColumns = $table->columns();

列使用

$column = $table->column('my_column_name');

//returns a stdClass instance refecting a record from the schema info of your database.
$column->info();

//get the table the column belongs to.
$parentTable = $column->table();