承接 noud/schema 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

noud/schema

Composer 安装命令:

composer require noud/schema

包简介

Read database schema, table and column metadata in Laravel or plain PHP.

README 文档

README

... a very lightweight one. Iterate through all your databases, tables and columns without having to lookup the correct query syntax for your specific database system.

composer require dfba/schema

Examples

If you're using Laravel this will be extra easy:

Add the following line to the 'providers' section of your app.php config file:

Dfba\Schema\Laravel\SchemaServiceProvider::class,

From this point on you can inject Dfba\Schema\Schema into your application. For example:

<?php
namespace App\Http\Controllers;

use Illuminate\Routing\Controller as BaseController;

use Dfba\Schema\Schema; // Very crucial line

class ExampleController extends BaseController {
    
	public function test(Schema $schema) {
		// --------------^ HERE


		// Some demo code:
		echo "<b>". $schema->getName() ."</b><br>";

		foreach ($schema->getTables() as $table) {
			echo "__ <b>". $table->getName() ."</b><br>";

			foreach ($table->getColumns() as $column) {
				echo "__ __ <b>". 
					$column->getName() ."</b><br>";

				echo "__ __ __ <i>dataType:</i> ".
					$column->getDataType() ."<br>";
				echo "__ __ __ <i>unsigned:</i> ".
					$column->getUnsigned() ."<br>";
				echo "__ __ __ <i>zerofill:</i> ".
					$column->getZerofill() ."<br>";
				echo "__ __ __ <i>nullable:</i> ".
					$column->getNullable() ."<br>";
				echo "__ __ __ <i>defaultValue:</i> ".
					$column->getDefaultValue() ."<br>";
				echo "__ __ __ <i>options:</i> ".
					implode(', ', $column->getOptions() ?: []) ."<br>";
				echo "__ __ __ <i>autoIncrement:</i> ".
					$column->getAutoIncrement() ."<br>";
				echo "__ __ __ <i>maximumLength:</i> ".
					$column->getMaximumLength() ."<br>";
				echo "__ __ __ <i>minimumValue:</i> ".
					$column->getMinimumValue() ."<br>";
				echo "__ __ __ <i>maximumValue:</i> ".
					$column->getMaximumValue() ."<br>";
				echo "__ __ __ <i>precision:</i> ".
					$column->getPrecision() ."<br>";
				echo "__ __ __ <i>scale:</i> ".
					$column->getScale() ."<br>";
				echo "__ __ __ <i>characterSet:</i> ".
					$column->getCharacterSet() ."<br>";
				echo "__ __ __ <i>collation:</i> ".
					$column->getCollation() ."<br>";
				echo "__ __ __ <i>comment:</i> ".
					$column->getComment() ."<br>";
			}
		}

	}
}

Injecting Dfba\Schema\Schema in your code will fetch the schema for the currently configured database. That means you'll need to have a database set up and configured ;)

Note: it's possible to read the database metadata for any open connection, not just the default Laravel one. The Dfba\Schema\Manager will happily burp out Schemas as long as you feed it PDO connections and database names:

<?php
namespace App\Http\Controllers;

use Illuminate\Routing\Controller as BaseController;

use Dfba\Schema\Manager; // Very crucial line

class ExampleController extends BaseController {

	public function test(Manager $manager) {
		
		$anyRandomPdo = \DB::connection()->getReadPdo();
		$someSchemaName = 'example';

		$schema = $manager->getSchema($anyRandomPdo, $someSchemaName);

		var_dump($schema);
		
	}
}

Good plain ol' PHP (or other frameworks)

I haven't forgotten about you:

$schemaManager = new Dfba\Schema\Manager();
$anyRandomPdo = new PDO("mysql:host=localhost;dbname=example", "username", "password");
$someSchemaName = 'example';

$schema = $schemaManager->getSchema($anyRandomPdo, $someSchemaName);

var_dump($schema);

You should be aware of that the Dfba\Schema\Manager caches retrieved schemas to prevent fetching the same data multiple times. If you create new Dfba\Schema\Manager instances over and over again, you won't benefit from the cache.

Postgres, SQL Server, etc.?

Oh... yeah. MySQL and SQLite are the only databases currently implemented. I have extracted all the database specific code into it's own file, though. You want other databases implemented? Open an issue, or better yet: copy src/MySqlSchemaFactory.php and do it yourself. It's not that hard! You can do it! :)

noud/schema 适用场景与选型建议

noud/schema 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 55 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 09 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 noud/schema 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 noud/schema 我们能提供哪些服务?
定制开发 / 二次开发

基于 noud/schema 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 55
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-09-28