PHPackages                             kdevhubin/pdoentitygenerator - 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. [CLI &amp; Console](/categories/cli)
4. /
5. kdevhubin/pdoentitygenerator

ActiveComposer-plugin[CLI &amp; Console](/categories/cli)

kdevhubin/pdoentitygenerator
============================

CLI tool to generate PHP PDO Entity and Repository classes from database tables

v1.6(1mo ago)014MITPHPPHP &gt;=8.4

Since May 28Pushed 1mo agoCompare

[ Source](https://github.com/krishnadevhub/pdo-entity-generator)[ Packagist](https://packagist.org/packages/kdevhubin/pdoentitygenerator)[ RSS](/packages/kdevhubin-pdoentitygenerator/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (7)Dependencies (2)Versions (9)Used By (0)

PDO Entity Generator
====================

[](#pdo-entity-generator)

A CLI tool to generate PHP PDO Entity and Repository classes from database tables. Works in any PHP project — no framework required.

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Getting Started](#getting-started)
    - [Installation](#installation)
    - [Configuration](#configuration)
    - [Quick Start](#quick-start)
- [Usage](#usage)
    - [Generating Entities](#generating-entities)
    - [Generated Entity Example](#generated-entity-example)
    - [Generated Repository Example](#generated-repository-example)
    - [Generated PdoFactory](#generated-pdofactory)
    - [Using Generated Classes](#using-generated-classes)
- [Reference](#reference)
    - [Configuration Options](#configuration-options)
    - [Naming Conventions](#naming-conventions)
    - [Type Mapping](#type-mapping)
- [Architecture](#architecture)
- [Contributing](#contributing)
    - [Development Setup](#development-setup)
    - [Project Structure](#project-structure)
    - [Coding Standards](#coding-standards)
    - [Adding a New SQL Type Mapping](#adding-a-new-sql-type-mapping)
    - [Modifying Generated Code Templates](#modifying-generated-code-templates)
    - [Testing Changes Locally](#testing-changes-locally)
    - [Submitting Changes](#submitting-changes)
- [Troubleshooting](#troubleshooting)
- [Licence](#licence)

---

Requirements
------------

[](#requirements)

- PHP 8.4 or higher
- PDO extension (`ext-pdo`)
- MySQL / MariaDB database
- Composer 2.x

Getting Started
---------------

[](#getting-started)

### Installation

[](#installation)

Install the package via Composer:

```
composer require kdevhubin/pdoentitygenerator
```

This package is a **Composer Plugin**. On first install, Composer will prompt you to allow the plugin:

```
Do you trust "kdevhubin/pdoentitygenerator" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json)

```

Type `y` to allow it. You can also pre-authorise the plugin by adding it to your project's `composer.json`:

```
{
    "config": {
        "allow-plugins": {
            "kdevhubin/pdoentitygenerator": true
        }
    }
}
```

Once allowed, the plugin automatically creates `config/pdoentitygenerator.yaml` with default settings. There is no manual setup step required.

### Configuration

[](#configuration)

Open `config/pdoentitygenerator.yaml` in your project root and update it with your database credentials:

```
database:
    host: 127.0.0.1
    port: 3306
    dbname: my_database
    username: root
    password: secret
    driver: mysql

output:
    entity_namespace: App\Entity
    repository_namespace: App\Repository
    factory_namespace: App\Factory
    entity_directory: src/Entity
    repository_directory: src/Repository
    factory_directory: src/Factory
```

> **Important**: The `database.dbname` field is required. The generator will not run without it.

### Quick Start

[](#quick-start)

```
# 1. Install the package (config file is auto-created via Composer Plugin)
composer require kdevhubin/pdoentitygenerator
# When prompted, type 'y' to allow the plugin

# 2. Update config/pdoentitygenerator.yaml with your database credentials
nano config/pdoentitygenerator.yaml

# 3. Generate entity and repository for a table
vendor/bin/pdoentitygenerator table users

# Output:
#   Created: src/Entity/Users.php
#   Created: src/Repository/UsersRepository.php
#   Created: src/Factory/PdoFactory.php
```

---

Usage
-----

[](#usage)

### Generating Entities

[](#generating-entities)

Run the CLI command with the `table` subcommand followed by the database table name:

```
vendor/bin/pdoentitygenerator table
```

The tool will:

1. Read `config/pdoentitygenerator.yaml` for database connection details
2. Connect to the database via PDO
3. Inspect the table schema (column names, types, nullability)
4. Generate an Entity class, a Repository class, and a PdoFactory class in the configured output directories

#### Example

[](#example)

```
vendor/bin/pdoentitygenerator table test_my_table
```

This generates:

- `src/Entity/TestMyTable.php` — POPO with typed properties, getters, and setters
- `src/Repository/TestMyTableRepository.php` — PDO-based CRUD repository
- `src/Factory/PdoFactory.php` — framework-agnostic factory for creating configured PDO connections (skipped if already exists)

### Generated Entity Example

[](#generated-entity-example)

For a table `test_my_table` with columns `id`, `name`, `email`, and `created_at`:

```
