lane4core/dbschema

A flexible package for analyzing and managing database schemas (PDO-based) with support for MySQL/MariaDB, PostgreSQL, and SQLite

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

pkg:composer/lane4core/dbschema

1.0.0 2025-10-19 16:30 UTC

This package is auto-updated.

Last update: 2025-10-19 16:34:50 UTC


README

A flexible package for analyzing and managing database schemas (PDO-based) with support for MySQL/MariaDB, PostgreSQL, and SQLite.

Overview

This package provides a unified API to consistently retrieve schema information from different database systems. It includes specific implementations for common database drivers (MySQL/MariaDB, PostgreSQL, SQLite).

Purpose:

  • Unified retrieval of schema information (tables, columns, indexes, foreign keys)
  • Standardization of data structures across different database systems
  • Ability to extend behavior with custom repository implementations
  • High testability and interchangeability

Supported Database Types

The package includes schema repository implementations for the following database types:

  • MySQL / MariaDBMySql
  • PostgreSQLPostgres
  • SQLiteSqLite

Each repository class handles database-specific schema queries and returns results in consistent structures.

Installation

Using Composer:

composer require lane4core/dbschema

For local development:

git clone https://github.com/Lane4core/DbSchema.git
cd DbSchema
composer install

Configuration

DbSchema works with an existing PDO connection.

use PDO;

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

Examples

Basic Usage

use Lane4core\DbSchema\DbSchema;

// Create PDO connection
$pdo = /* your PDO instance */;

$schema = new DbSchema($pdo);

// Retrieve all tables
$tables = $schema->tables();
print_r($tables);

// Retrieve columns of a table
$columns = $schema->columns('users');
print_r($columns);

// Retrieve specific columns
$specificColumns = $schema->columns('users', ['id', 'name', 'email']);
print_r($specificColumns);

// Retrieve indexes of a table
$indexes = $schema->indexes('users');
print_r($indexes);

// Retrieve foreign keys of a table
$foreignKeys = $schema->foreignKeys('orders');
print_r($foreignKeys);

// Get PHP type mapping for a DB type
$phpType = $schema->fieldType('VARCHAR');
echo $phpType; // "string"

Tests

The project includes PHPUnit tests located under tests/.

make phpunit

CI & Code Quality

The repository uses or recommends the following tools:

  • PHPStan for static analysis (Level 8)
  • PHPCS for code style checks
  • PHPUnit for unit tests (coverage 100%)
  • GitHub Actions for CI/CD

Typical CI steps:

  1. composer install
  2. make phpcs
  3. make phpstan
  4. make phpunit-coverage

License

This project is licensed under the MIT License – see LICENSE in the repository.

Enjoy and succeed with DbSchema!