PHPackages                             eril/tbl-class - 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. eril/tbl-class

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

eril/tbl-class
==============

CLI tool that Generates stable PHP constants from your database schema to improve IDE autocomplete and avoid SQL typos.

v1.1.0(5mo ago)143MITPHPPHP &gt;=8.1CI passing

Since Jan 18Pushed 1mo agoCompare

[ Source](https://github.com/erilshackle/tbl-class-php)[ Packagist](https://packagist.org/packages/eril/tbl-class)[ Docs](https://github.com/erilshackle/tbl-class-php)[ RSS](/packages/eril-tbl-class/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

Tbl::class
==========

[](#tblclass)

### Type-safe database schema constants para PHP

[](#type-safe-database-schema-constants-para-php)

[![Latest Version](https://camo.githubusercontent.com/4d64340e7e83a7f98bcccc63cb346f1dbbb25704b97e2e5ef1288ed99f261a03/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6572696c2f74626c2d636c617373)](https://packagist.org/packages/eril/tbl-class)[![PHP Version](https://camo.githubusercontent.com/8d21bcad7ea38f43cbcfb4b75a530b7bc510336745287f3e7148185e2b88f5b0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6572696c2f74626c2d636c617373)](https://packagist.org/packages/eril/tbl-class)[![License](https://camo.githubusercontent.com/ce7031f5d2948cf8fadf90912fbedfd2ccc45613a63afdf116626b5801004cd2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6572696c2f74626c2d636c617373)](https://packagist.org/packages/eril/tbl-class)[![Downloads](https://camo.githubusercontent.com/9b8b905434692b29b240a6ab0de73154fd34aa9fdc653306b7c8134f0fa79d7d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6572696c2f74626c2d636c617373)](https://packagist.org/packages/eril/tbl-class)[![Stars](https://camo.githubusercontent.com/f0d68bdd9d62924315caba74247d0f2446569709b425035ff1c134fe01906e15/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6572696c736861636b6c652f74626c2d636c6173732d7068703f7374796c653d736f6369616c)](https://github.com/erilshackle/tbl-class-php)

`tbl-class` generates **immutable PHP entry-point classes** that map your database schema
(tables, columns and relations) into **compile-safe constants**.

It provides a stable abstraction layer between your database and your application code, eliminating fragile string literals and runtime schema assumptions.

---

Why tbl-class?
--------------

[](#why-tbl-class)

Database-driven PHP applications commonly rely on raw strings:

```
SELECT * FROM users WHERE created_at > ?
```

This approach is fragile:

- typos are silent
- refactors are risky
- schema changes break code at runtime
- no compile-time guarantees

`tbl-class` replaces string-based access with **generated constants derived directly from the database schema**:

```
Tbl::users                // users
Tbl::users__created_at    // created_at
Tbl::fk__posts__users     // user_id
Tbl::on__contacts__users  // contacts.user_id = users.id
```

Your application code becomes **schema-aware, explicit and refactor-safe**.

---

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

[](#installation)

```
composer require eril/tbl-class --dev
```

---

Usage
-----

[](#usage)

### First run

[](#first-run)

```
./vendor/bin/tbl-class
```

On first execution, a configuration file is generated:

```
tblclass.yaml

```

**Edit** the file, configure your **database connection**, then run the command again.

---

### Generate schema constants

[](#generate-schema-constants)

```
./vendor/bin/tbl-class
```

This command:

- connects to the database
- introspects the schema
- generates PHP constants according to your configuration

---

### Check for schema changes (CI-friendly)

[](#check-for-schema-changes-ci-friendly)

```
./vendor/bin/tbl-class --check
```

This mode:

- does **not** generate files
- compares the current database schema with the last generated version
- exits with a non-zero status code if changes are detected

Designed for CI pipelines and deployment safety checks.

> It's not meant to be checked overtime, but only

---

Configuration
-------------

[](#configuration)

All configuration lives in `tblclass.yaml`.

A clean template is auto-generated on first run:

```
# Enable or disable generation
enabled: true

# Optional: include a PHP file before execution
include: null

# ------------------------------------------------------------
# Database configuration
# ------------------------------------------------------------
database:

  # Optional custom connection resolver
  # Must return a PDO instance
  # Example: App\\Database::getConnection
  connection: null

  driver: mysql            # mysql | pgsql | sqlite

  # MySQL / PostgreSQL
  host: env(DB_HOST)       # default: localhost
  port: env(DB_PORT)       # default: 3306 | 5432
  name: env(DB_NAME)       # database name
  user: env(DB_USER)
  password: env(DB_PASS)

  # SQLite only
  # path: env(DB_PATH)

# ------------------------------------------------------------
# Output configuration
# ------------------------------------------------------------
output:

  # Output directory
  path: "./"

  # PHP namespace for generated classes
  namespace: ""

  # ⚠ IMPORTANT
  # This strategy defines ALL generated constant names.
  # Changing it later WILL rename constants and MAY break code.
  #
  # Strategies:
  # - full   → table, table__column, fk__table__references
  # - short  → table, tbl__column,   fk__table__references
  # - abbr   → table, tbl__column,   fk__tbl__ref
  # - alias  → table, t__column,     fk__t__r
  # - upper  → TABLE, TABLE__COLUMN, FK__TABLE__REFERENCES
  naming:
    strategy: full
```

📘 **Full configuration reference:**

---

Generated Output
----------------

[](#generated-output)

Depending on the enabled generators, `tbl-class` produces PHP classes containing:

- table name constants
- column name constants
- foreign key references
- JOIN expressions derived from relations

Example usage:

```
Tbl::users                       // returns "users"
Tbl::users('u')                    // returns "users AS u"
Tbl::users__email                // returns "email"
Tbl::fk__users__roles            // returns "role_id" or whataver you named it in DB
Tbl::on__users__roles()          // returns "users.role_id = roles.id"
Tbl::on__users__roles('u', 'r')  // // returns "u.role_id = r.id"
```

All output is **deterministic**, **static**, and **runtime-free**.

---

Autoloading
-----------

[](#autoloading)

After generation, add **one** of the following to your `composer.json`.

### PSR-4

[](#psr-4)

```
"autoload": {
  "psr-4": {
    "Tbl\\": "path/to/Tbl/"
  }
}
```

### Files

[](#files)

```
"autoload": {
  "files": [
    "path/to/Tbl.php"
  ]
}
```

Then run:

```
composer dump-autoload
```

---

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

[](#documentation)

All advanced topics, design decisions and future extensions are documented in the Wiki:

📚 [Wiki](https://github.com/erilshackle/tbl-class-php/wiki)

---

What tbl-class is not
---------------------

[](#what-tbl-class-is-not)

- ❌ Not an ORM
- ❌ Not a query builder
- ❌ Not a migration tool
- ❌ Not a runtime schema inspector

It is a **compile-time schema contract for PHP applications**.

---

License
-------

[](#license)

MIT © 2026 Eril TS Carvalho

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance82

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

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

2

Last Release

160d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/74083037?v=4)[Eril TS Carvalho](/maintainers/erilshackle)[@erilshackle](https://github.com/erilshackle)

---

Top Contributors

[![erilshackle](https://avatars.githubusercontent.com/u/74083037?v=4)](https://github.com/erilshackle "erilshackle (31 commits)")

---

Tags

auto-generationci-cdclicomposerconstantsdatabasedb-consistency-checkerdb-constantsdevelopment-toolsgeneratoride-autocompletemysqlorm-alternativephpphp-libraryschemasqlitetype-safetyphpclischemaautocompletemysqlsqlitesqlPSR-4code-generationdeveloper-experiencedatabase-schemaraw-sqldatabase-constants

### Embed Badge

![Health badge](/badges/eril-tbl-class/health.svg)

```
[![Health](https://phpackages.com/badges/eril-tbl-class/health.svg)](https://phpackages.com/packages/eril-tbl-class)
```

###  Alternatives

[cycle/orm

PHP DataMapper ORM and Data Modelling Engine

1.3k918.1k78](/packages/cycle-orm)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1189.8k](/packages/rcsofttech-audit-trail-bundle)[aura/sqlschema

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

44243.2k4](/packages/aura-sqlschema)[watheqalshowaiter/model-fields

Get model fields fast — required, nullable, or default

402.1k](/packages/watheqalshowaiter-model-fields)

PHPackages © 2026

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