定制 jardistools/dbschema 二次开发

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

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

jardistools/dbschema

最新稳定版本:v1.0.1

Composer 安装命令:

composer require jardistools/dbschema

包简介

Database schema introspection and DDL export for MySQL, MariaDB, PostgreSQL, and SQLite

README 文档

README

Build Status License: MIT PHP Version PHPStan Level PSR-12 Coverage

Part of Jardis — the Domain-Driven Design platform for PHP. You model your domain; Jardis generates the production-ready hexagonal code (DTOs, Command/Query handlers, repositories, persistence). This package is part of the open-source foundation that generated code runs on.

Database schema analysis for PHP — introspects and exports the structure of live databases via PDO. Reads tables, columns, indexes, and foreign keys, then emits SQL (CREATE TABLE), JSON, or PHP arrays for schema import, diffing, or as the schema on-ramp for hexagonal code generation. Dialect-aware for MySQL, MariaDB, PostgreSQL, and SQLite.

Features

  • Schema Introspection — reads tables, columns, indexes, and foreign keys from a live database
  • DDL Export — generates CREATE TABLE SQL scripts with dialect-correct syntax
  • JSON Export — structured JSON output suitable for storage, diffing, or feeding Jardis code generation
  • Array Export — PHP array representation for programmatic processing
  • Multi-Database — MySQL, MariaDB, PostgreSQL, and SQLite via automatic PDO driver detection
  • Abstract Type MappingfieldType() normalises driver-specific column types to portable abstract types
  • Field Type Normalization — consistent column metadata regardless of database vendor

Installation

composer require jardistools/dbschema

Quick Start

use JardisTools\DbSchema\DbSchemaReader;
use JardisTools\DbSchema\DbSchemaExporter;

$pdo = new PDO('mysql:host=localhost;dbname=shop', 'user', 'pass');

$reader   = new DbSchemaReader($pdo);
$exporter = new DbSchemaExporter($reader);

// List all tables
$tables = $reader->tables();

// Export schema as JSON (suitable as Jardis code-generation input)
$json = $exporter->toJson($tables, prettyPrint: true);
file_put_contents('schema.json', $json);

Advanced Usage

use JardisTools\DbSchema\DbSchemaReader;
use JardisTools\DbSchema\DbSchemaExporter;

$pdo    = new PDO('pgsql:host=localhost;dbname=shop', 'user', 'pass');
$reader = new DbSchemaReader($pdo);

// Inspect a single table
$columns    = $reader->columns('orders');
$indexes    = $reader->indexes('orders');
$foreignKeys = $reader->foreignKeys('orders');

// Translate a driver-specific type to a portable abstract type
$abstractType = $reader->fieldType('character varying'); // → 'string'

// Export selected tables as SQL DDL
$exporter = new DbSchemaExporter($reader);
$ddl = $exporter->toSql(['orders', 'order_lines', 'customers']);
echo $ddl;
// CREATE TABLE "orders" ( ... );
// CREATE TABLE "order_lines" ( ... );

// Export as PHP array for custom processing
$schema = $exporter->toArray(['orders', 'order_lines']);
// [
//   'version'   => '1.0',
//   'generated' => '2025-01-16 10:30:00',
//   'tables'    => ['orders' => ['columns' => [...], 'indexes' => [...], 'foreignKeys' => [...]]]
// ]

// Feed the schema array into Jardis for code generation
use JardisTools\Builder\Config\DatabaseSchema;
$databaseSchema = DatabaseSchema::fromArray($schema);

Documentation

Full documentation, guides, and API reference:

docs.jardis.io/en/tools/dbschema

License

This package is licensed under the MIT License.

Jardis · Documentation · Headgent

KI-gestützte Entwicklung

Dieses Package liefert einen Skill für Claude Code, Cursor, Continue und Aider mit. Installation im Konsumentenprojekt:

composer require --dev jardis/dev-skills

Mehr Details: https://docs.jardis.io/en/skills

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固