jardispsr/dbschema

This package provides dbSchema interfaces for a domain driven design approach

Installs: 61

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

pkg:composer/jardispsr/dbschema

1.0.0 2025-12-16 14:54 UTC

This package is auto-updated.

Last update: 2025-12-16 15:03:13 UTC


README

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

PHP library providing database schema interfaces for Domain Driven Design (DDD) approaches.

Installation

composer require jardispsr/dbschema

Requirements

  • PHP >= 8.2

Interfaces

This package provides two complementary interfaces for database schema operations:

DbSchemaReaderInterface

Read and introspect database schema information:

use JardisPsr\DbSchema\DbSchemaReaderInterface;

class YourSchemaReader implements DbSchemaReaderInterface
{
    public function tables(): ?array
    {
        // Return list of all tables in the database
    }

    public function columns(string $container, ?array $fields = null): ?array
    {
        // Return columns for a table, optionally filtered by specified fields
    }

    public function indexes(string $container): ?array
    {
        // Return indexes for a table
    }

    public function foreignKeys(string $container): ?array
    {
        // Return foreign keys for a table
    }

    public function fieldType(string $fieldType): ?string
    {
        // Map database field types to PHP types (e.g., 'varchar' -> 'string')
    }

    public function getDriverName(): string
    {
        // Return the name of the database driver (e.g., 'mysql', 'pgsql', 'sqlite')
    }
}

DbSchemaExporterInterface

Export database schema in various formats:

use JardisPsr\DbSchema\DbSchemaExporterInterface;

class YourSchemaExporter implements DbSchemaExporterInterface
{
    public function toSql(array $tables): string
    {
        // Export schema as SQL DDL script
    }

    public function toJson(array $tables, bool $prettyPrint = false): string
    {
        // Export schema as JSON
    }

    public function toArray(array $tables): array
    {
        // Export schema as PHP array
    }
}

Terminology

  • Container: Database-agnostic term for "table" (aligned with DDD principles)
  • Fields: Specific column attributes to retrieve when querying columns

Development

This project uses Docker for all development operations. See CLAUDE.md for detailed instructions.

Quick Start

# Install dependencies
make install

# Run code quality checks
make phpcs
make phpstan

# Access container shell
make shell

Code Quality Standards

  • PHP Version: 8.2+ (development: 8.3)
  • Coding Standard: PSR-12
  • Static Analysis: PHPStan Level 8
  • Strict Types: Required in all files

Contributing

  1. Follow branch naming: feature/[ticket]_description or fix/[ticket]_description
  2. Pre-commit hooks enforce code standards automatically
  3. All PRs must pass PHPCS and PHPStan checks

License

MIT

Support