PHPackages                             jardistools/dbschema - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. jardistools/dbschema

ActiveLibrary[Database &amp; ORM](/categories/database)

jardistools/dbschema
====================

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

v1.0.5(1mo ago)043MITPHPPHP &gt;=8.2CI passing

Since Jun 2Pushed 2mo agoCompare

[ Source](https://github.com/jardisTools/dbSchema)[ Packagist](https://packagist.org/packages/jardistools/dbschema)[ Docs](https://jardis.io)[ RSS](/packages/jardistools-dbschema/feed)WikiDiscussions main Synced 4w ago

READMEChangelog (6)Dependencies (15)Versions (10)Used By (0)

Jardis DbSchema
===============

[](#jardis-dbschema)

[![Build Status](https://github.com/jardisTools/dbSchema/actions/workflows/ci.yml/badge.svg)](https://github.com/jardisTools/dbSchema/actions/workflows/ci.yml/badge.svg)[![License: MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](LICENSE.md)[![PHP Version](https://camo.githubusercontent.com/a68b290dcc313d698dc138a1111aa83eee2f143605449d7e8b5416ea6f88558f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344382e322d3737374242342e737667)](https://www.php.net/)[![PHPStan Level](https://camo.githubusercontent.com/c51bda247654363d3e30bc352674dd761a9557803a14af0226eb411d6dc0006b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c253230382d627269676874677265656e2e737667)](phpstan.neon)[![PSR-12](https://camo.githubusercontent.com/34b10db0caa29bacd49bda5c437a8de95385f036f3230b31fa605326e18da22c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f64652532305374796c652d5053522d2d31322d626c75652e737667)](phpcs.xml)[![Coverage](https://camo.githubusercontent.com/1571585e3d98fea87b3bff45751762259a4f746e6e3f55a661e223c45464ec15/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f7665726167652d39342e32332532352d627269676874677265656e2e737667)](https://github.com/jardisTools/dbSchema)

> Part of **[Jardis](https://jardis.io)** — 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
--------

[](#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 Mapping** — `fieldType()` normalises driver-specific column types to portable abstract types
- **Field Type Normalization** — consistent column metadata regardless of database vendor

---

Installation
------------

[](#installation)

```
composer require jardistools/dbschema
```

Quick Start
-----------

[](#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
--------------

[](#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' => [...]]]
// ]
```

Documentation
-------------

[](#documentation)

Full documentation, guides, and API reference:

**[docs.jardis.io/en/tools/dbschema](https://docs.jardis.io/en/tools/dbschema)**

License
-------

[](#license)

This package is licensed under the [MIT License](LICENSE.md).

---

**[Jardis](https://jardis.io)** · [Documentation](https://docs.jardis.io) · [Headgent](https://headgent.com)

AI-Assisted Development
-----------------------

[](#ai-assisted-development)

This package ships with a skill for Claude Code, Cursor, Continue, and Aider. Install it in your consuming project:

```
composer require --dev jardis/dev-skills
```

More details:

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance89

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~6 days

Total

6

Last Release

35d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e07a1b668e9e01ee6d1b85de7b3be1c2513f68aae9494b2011d1592104d5daa0?d=identicon)[jardis](/maintainers/jardis)

---

Top Contributors

[![Headgent](https://avatars.githubusercontent.com/u/245725954?v=4)](https://github.com/Headgent "Headgent (1 commits)")

---

Tags

phpschemadatabasemysqlsqlitepostgrespdoDomain Driven DesignddlHeadgentjardisdatabase-introspection

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jardistools-dbschema/health.svg)

```
[![Health](https://phpackages.com/badges/jardistools-dbschema/health.svg)](https://phpackages.com/packages/jardistools-dbschema)
```

###  Alternatives

[aura/sqlschema

Provides facilities to read table names and table columns from a database using PDO.

41245.4k4](/packages/aura-sqlschema)[aura/sqlquery

Object-oriented query builders for MySQL, Postgres, SQLite, and SQLServer; can be used with any database connection library.

4573.2M40](/packages/aura-sqlquery)[popphp/pop-db

Pop Db Component for Pop PHP Framework

1817.4k14](/packages/popphp-pop-db)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
