定制 sculptor/db-visualizer 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

sculptor/db-visualizer

最新稳定版本:v0.2.2

Composer 安装命令:

composer require sculptor/db-visualizer

包简介

Read-only, framework-agnostic database schema visualizer for PHP

README 文档

README

DB Visualizer is a read-only, framework-agnostic database schema introspection and visualization library for PHP .

It is designed to safely inspect database structure only (tables, columns, indexes, foreign keys) using Core PHP + PDO , with zero data access and zero schema mutation.

✨ Features

  • 🔍 Schema-only introspection
    • Tables
    • Columns
    • Indexes
    • Foreign keys
  • 🔐 Security-first design
    • Read-only by design
    • No data queries
    • Visualization disabled by default
  • 🧩 Framework-agnostic
    • Works with Core PHP
    • No Laravel / Symfony / CI dependency
  • 🔌 Adapter-based architecture
    • MySQL adapter included
    • Easy to extend for PostgreSQL, SQLite
  • 📦 Composer-first
    • PSR-4 autoloading
    • Clean dependency graph
  • 🧪 Deterministic output
    • Stable JSON for testing & tooling

📦 Installation

composer require sculptor/db-visualizer

Requirements

  • PHP 8.1+
  • PDO extension
  • Supported DB: MySQL / MariaDB (initial release)

🚀 Quick Start (JSON Schema Preview)

<?php
require 'vendor/autoload.php';

use Sculptor\DbVisualizer\Services\ConnectionHandler;
use Sculptor\DbVisualizer\Services\Visualizer;
use Sculptor\DbVisualizer\Renderers\JSONRenderer;

// Create PDO connection
$pdo = new PDO(
    'mysql:host=localhost;dbname=my_database',
    'username',
    'password',
    [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    ]
);

// Initialize connection handler
$connection = new ConnectionHandler($pdo, 'my_database');

// Extract schema (metadata only)
$schema = $connection->getIntrospector()->schema();

// Create visualizer (disabled by default)
$visualizer = new Visualizer($schema);

// Explicitly enable visualization
$visualizer->enable();

// Render JSON
$renderer = new JSONRenderer();

header('Content-Type: application/json');
echo $visualizer->render($renderer);

🌐 HTML Schema Viewer

To view your schema in the browser with HTML:

<?php
require 'vendor/autoload.php';

use Sculptor\DbVisualizer\Services\ConnectionHandler;
use Sculptor\DbVisualizer\Services\Visualizer;

$pdo = new PDO(
    'mysql:host=localhost',
    'username',
    'password'
);

$connection = new ConnectionHandler($pdo, 'my_database');
$schema = $connection->getIntrospector()->schema();

$visualizer = new Visualizer($schema);
$visualizer->enable();

// Use convenience method for pre-configured HTML renderer
header('Content-Type: text/html; charset=UTF-8');
echo $visualizer->render($visualizer->getHTMLRenderer());

The HTML output is:

  • Server-side rendered (no JavaScript)
  • Fully escaped for XSS safety
  • Self-contained with minimal inline styles
  • Database switcher included (if multiple databases available)
  • Deterministic for consistent output

Multi-Database Switching

The HTML viewer includes a database selector dropdown when multiple databases are available. Users can switch databases via the ?database= query parameter:

http://localhost:8000/your-script.php?database=my_database
http://localhost:8000/your-script.php?database=another_database

The library automatically:

  1. Detects the ?database= parameter
  2. Fetches schema for the requested database
  3. Renders the appropriate database's tables and structure
  4. Includes available databases in the selector dropdown

🧱 Architecture Overview

PDO
 ↓
ConnectionHandler
 ↓
DriverAdapter (MySQL)
 ↓
Schema (Immutable Snapshot)
 ↓
Visualizer (Explicit Enable Gate)
 ↓
Renderer (JSON / HTML / DOT)

Key Design Principles

  • Contracts first (interfaces over implementations)
  • Adapters isolate database-specific logic
  • Renderers never access the database
  • Schema objects are immutable
  • No side effects

🔐 Security Model

DB Visualizer is intentionally restrictive:

  • ❌ No row or data access
  • ❌ No schema mutation
  • ❌ No file I/O
  • ❌ No auto-execution or auto-exposure

Visualization Gate

Rendering is disabled by default :

$visualizer->render($renderer); // ❌ throws exception
$visualizer->enable();
$visualizer->render($renderer); // ✅ allowed

This prevents accidental exposure in production environments.

📤 Output Formats

✅ JSON (Available)

  • Deterministic ordering
  • Fully escaped identifiers
  • Tooling & API friendly

✅ HTML (Available)

  • Server-side rendering (no JavaScript)
  • Semantic HTML with minimal inline styles
  • Fully escaped identifiers (XSS-safe)
  • Responsive, readable layout

⏳ Planned

  • DOT / GraphViz (ER diagrams)

🧩 Extending the Library

Custom Database Adapter

Implement the DriverAdapter and SchemaIntrospector contracts, then register:

$resolver->register('pgsql', PostgresAdapter::class);

Custom Renderer

Implement the Renderer contract:

class MyRenderer implements Renderer
{
    public function getName(): string {}
    public function getMimeType(): string {}
    public function render(Schema $schema): string {}
}

🧪 Testing Philosophy

The library is designed to be testable without :

  • Frameworks
  • Database servers (PDO can be mocked)
  • Filesystem access
  • Global state

JSON output is deterministic to support snapshot testing.

🗺 Roadmap

  • HTML Renderer (v0.2.0)
  • PostgreSQL Adapter
  • SQLite Adapter
  • DOT / ER Diagram Renderer
  • PHPUnit test suite
  • CLI (optional, last)

📄 License

MIT License © sculptorofcode

🤝 Contributing

Contributions are welcome, especially:

  • New database adapters
  • Renderers
  • Tests
  • Performance improvements

Please keep contributions:

  • Framework-agnostic
  • Read-only
  • Security-first

⭐ Why This Library Exists

Most schema visualizers are:

  • Framework-coupled
  • UI-first
  • Unsafe by default

DB Visualizer is built as a core infrastructure tool :

  • Minimal
  • Auditable
  • Extensible
  • Safe

sculptor/db-visualizer 适用场景与选型建议

sculptor/db-visualizer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 sculptor/db-visualizer 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-13