PHPackages                             rotexsoft/leanorm-cli - 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. rotexsoft/leanorm-cli

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

rotexsoft/leanorm-cli
=====================

Command-line tool for rotexsoft/leanorm for generating Model, Record &amp; Collection Classes for tables in a specified database.

4.0.2(1mo ago)0107BSD-3-ClausePHPPHP &gt;=8.2.0CI passing

Since Dec 31Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/rotexsoft/leanorm-cli)[ Packagist](https://packagist.org/packages/rotexsoft/leanorm-cli)[ Docs](https://github.com/rotexsoft/leanorm-cli)[ RSS](/packages/rotexsoft-leanorm-cli/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (10)Dependencies (17)Versions (24)Used By (0)

[![Run PHP Tests and Code Quality Tools](https://github.com/rotexsoft/leanorm-cli/actions/workflows/php.yml/badge.svg)](https://github.com/rotexsoft/leanorm-cli/actions/workflows/php.yml) [![GitHub release (latest SemVer)](https://camo.githubusercontent.com/6cab7ddc45aaa7ed58db0886ca19c6655b0e5a478130852a056fa88f5a1dc029/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f726f746578736f66742f6c65616e6f726d2d636c69)](https://camo.githubusercontent.com/6cab7ddc45aaa7ed58db0886ca19c6655b0e5a478130852a056fa88f5a1dc029/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f726f746578736f66742f6c65616e6f726d2d636c69) [![GitHub](https://camo.githubusercontent.com/7d6652960b3c7c05f4422bd2c88d63913dee7aee9702f72935808c41f8dbb4d8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f726f746578736f66742f6c65616e6f726d2d636c69)](https://camo.githubusercontent.com/7d6652960b3c7c05f4422bd2c88d63913dee7aee9702f72935808c41f8dbb4d8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f726f746578736f66742f6c65616e6f726d2d636c69) [![Coverage Status](https://camo.githubusercontent.com/922543f573d09bd9fc6669fcbacad809804d37d077f595840b41cfe1a58e3754/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f726f746578736f66742f6c65616e6f726d2d636c692f62616467652e737667)](https://coveralls.io/github/rotexsoft/leanorm-cli) [![GitHub code size in bytes](https://camo.githubusercontent.com/86c62886a3e18f784714028334ce2634867f3306d88a3035ff26631c972c5f52/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f726f746578736f66742f6c65616e6f726d2d636c69)](https://camo.githubusercontent.com/86c62886a3e18f784714028334ce2634867f3306d88a3035ff26631c972c5f52/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f726f746578736f66742f6c65616e6f726d2d636c69) [![Packagist Downloads](https://camo.githubusercontent.com/8c41d136d397627cfa52a434b1980172578da63e827fd73fdbd060a3dd3627c7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f746578736f66742f6c65616e6f726d2d636c69)](https://camo.githubusercontent.com/8c41d136d397627cfa52a434b1980172578da63e827fd73fdbd060a3dd3627c7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f746578736f66742f6c65616e6f726d2d636c69) [![GitHub top language](https://camo.githubusercontent.com/64c766f06d57684fccdeef65076cd457d9ea8924028189a6e7af57f3a19c9f0a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f746f702f726f746578736f66742f6c65616e6f726d2d636c69)](https://camo.githubusercontent.com/64c766f06d57684fccdeef65076cd457d9ea8924028189a6e7af57f3a19c9f0a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f746f702f726f746578736f66742f6c65616e6f726d2d636c69) [![Packagist PHP Version Support](https://camo.githubusercontent.com/727c08f85f9968e3f62095a0d307ed1878cb49548b9321092de62f37aec24e5c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f726f746578736f66742f6c65616e6f726d2d636c69)](https://camo.githubusercontent.com/727c08f85f9968e3f62095a0d307ed1878cb49548b9321092de62f37aec24e5c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f726f746578736f66742f6c65616e6f726d2d636c69) [![GitHub commits since latest release (by date)](https://camo.githubusercontent.com/f137d18f82bf41c703921534fafe7b1ad91718fe4734efa23c9c394739994874/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6d6d6974732d73696e63652f726f746578736f66742f6c65616e6f726d2d636c692f6c6174657374)](https://camo.githubusercontent.com/f137d18f82bf41c703921534fafe7b1ad91718fe4734efa23c9c394739994874/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6d6d6974732d73696e63652f726f746578736f66742f6c65616e6f726d2d636c692f6c6174657374) [![GitHub last commit](https://camo.githubusercontent.com/4baa634776706c5c9edc4760d15179eb14d435b900190b792db735bcc381ddbf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f726f746578736f66742f6c65616e6f726d2d636c69)](https://camo.githubusercontent.com/4baa634776706c5c9edc4760d15179eb14d435b900190b792db735bcc381ddbf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f726f746578736f66742f6c65616e6f726d2d636c69) [![GitHub Release Date](https://camo.githubusercontent.com/2fbefc6d56f44e746dd4adc757f5e6c3d74cb167ffa5d4249da5dff0b5e602ce/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652d646174652f726f746578736f66742f6c65616e6f726d2d636c69)](https://camo.githubusercontent.com/2fbefc6d56f44e746dd4adc757f5e6c3d74cb167ffa5d4249da5dff0b5e602ce/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652d646174652f726f746578736f66742f6c65616e6f726d2d636c69) [![Libraries.io dependency status for GitHub repo](https://camo.githubusercontent.com/a8a2dfcbe06319f541c4928ad9c7a2a1a1481dc5250f28d8229773d8b26427d8/68747470733a2f2f696d672e736869656c64732e696f2f6c6962726172696573696f2f6769746875622f726f746578736f66742f6c65616e6f726d2d636c69)](https://libraries.io/github/rotexsoft/leanorm-cli)

LeanOrm Cli
===========

[](#leanorm-cli)

About
-----

[](#about)

This is a simple command line tool for creating [LeanOrm](https://github.com/rotexsoft/leanorm) Collection, Model &amp; Record classes for each table &amp; view in a specified database. This tool reads information about tables and views from the db &amp; uses that information to generate the desired earlier mentioned classes.

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

[](#installation)

> composer require --dev rotexsoft/leanorm-cli

Usage
-----

[](#usage)

- Create model, record &amp; collection classes for all tables &amp; views using the specified config

> php ./vendor/bin/generate-leanorm-classes.php /path/to/config.php

- Create model, record &amp; collection classes for a specified table or view using the specified config
    - Replace **table\_or\_view\_name** with the name of the table or view you want to generate classes for

> php ./vendor/bin/generate-leanorm-classes.php /path/to/config.php table\_or\_view\_name

You need to create a config file that will be passed to the command above. This config file must return an array with the minimum structure below:

```
return [
    'pdo' => [             // An array with a minimum of 1 item and a maximum of 4 items or an instance of the PDO class
        'sqlite::memory:', // 1st compulsory item is a dsn string to be passed as 1st arg to the PDO consructor
        'username',        // 2nd optional item is a username string to be passed as 2nd arg to the PDO consructor
        'password',        // 3rd optional item is a password string to be passed as 3rd arg to the PDO consructor
        [],                // 4th optional item is an options array to be passed as 4th arg to the PDO consructor
    ],

    'namespace' => null,              // Root Namespace classes will belong to. E.g. 'App\\DataSource'. Null means no namespace.
    'directory' => './model-classes', // Absolute or relative path to where classes are to be written
];
```

See [sample-config.php](sample-config.php) for the full structure of the array that should be returned by the config file. Each item in the sample config file is thoroughly described &amp; you can specify the ones you want in your own config file.

> **Note:** running the command multiple times will not lead to all previously generated classes being overwritten. The only files that get overwritten would be the ones ending with **FieldsMetadata.php**. If you want all classes to be regenerated, you would have to manually delete them before re-running the command.

> **Note:** when you modify table or view columns in your database and you have previously generated your classes using a config whose **store\_table\_col\_metadata\_array\_in\_file** entry has a value of **true**, you SHOULD re-run this tool with the same config to update all the table column metadata files (i.e. those ending with **FieldsMetadata.php**) so that your table / view column modifications are reflected in your application. This re-run will not modify your Model, Record &amp; collection class files.

The classes generated will have the directory structure below for a database with an **authors** table &amp; a **posts** table:

```
/path
    /where
        /classes
            /were
                /written
                |_________Authors
                |           |______AuthorsCollection.php     # Collection class for the authors table
                |           |______AuthorsModel.php          # Model class for the authors table
                |           |______AuthorRecord.php          # Record class for the authors table
                |           |______AuthorsFieldsMetadata.php # Metadata array for the authors table columns, ONLY generated when the config entry **store_table_col_metadata_array_in_file** has a value of **true**
                |
                |_________Posts
                            |______PostsCollection.php     # Collection class for the posts table
                            |______PostsModel.php          # Model class for the posts table
                            |______PostRecord.php          # Record class for the posts table
                            |______PostsFieldsMetadata.php # Metadata array for the posts table columns, ONLY generated when the config entry **store_table_col_metadata_array_in_file** has a value of **true**

```

Most of these classes will be empty, and are provided so you can extend their behavior if you wish. They also serve to assist IDEs with autocompletion of some typehints.

Custom Templates
----------------

[](#custom-templates)

You can override the templates used by this tool and provide your own instead. This lets you customize the code generation; for example, to add your own common methods or to extend intercessory classes.

The templates used by this tool are located [here](templates), you can look at them to have an idea of how to craft your custom templates. Your custom templates can be located in any directory / folder of your choosing but they must have the same names as the default template files, i.e:

- TypesCollection.php.tpl
- TypesModel.php.tpl
- TypeRecord.php.tpl

You do not have to override all the template files, you can just override the ones you want to customize, the ones you do not override will keep using the default template(s). For example, you may only want to override the Model template **TypesModel.php.tpl**, which will lead to the default Collection &amp; Record templates to continue being used for creating Collection &amp; Record classes, while your custom Model template would be used for creating Model classes.

You will need to specify the directory containing your custom template files in the config file earlier described by adding an item with the key **custom\_templates\_directory** like so:

```
return [
    'pdo' => [             // An array with a minimum of 1 item and a maximum of 4 items
        'sqlite::memory:', // 1st compulsory item is a dsn string to be passed as 1st arg to the PDO consructor
        'username',        // 2nd optional item is a username string to be passed as 2nd arg to the PDO consructor
        'password',        // 3rd optional item is a password string to be passed as 3rd arg to the PDO consructor
        [],                // 4th optional item is an options array to be passed as 4th arg to the PDO consructor
    ],

    'namespace' => null,              // Root Namespace classes will belong to. E.g. 'App\\DataSource'. Null means no namespace.
    'directory' => './model-classes', // Absolute or relative path to where classes are to be written
    'custom_templates_directory' => './path', // Absolute / relative path to a location containing 1 or more template files below
                                              // TypesModel.php.tpl, TypesCollection.php.tpl & TypeRecord.php.tpl
];
```

Below is a full list of variables / tokens that are present in the template files:

- **{{{COLLECTION\_EXTENDED}}}** will be substituted with the fully qualified class name of the collection each new collection class will extend. Default is **\\LeanOrm\\Model\\Collection**
- **{{{MODEL\_EXTENDED}}}** will be substituted with the fully qualified class name of the model each new model class will extend. Default is **\\LeanOrm\\Model**
- **{{{RECORD\_EXTENDED}}}** will be substituted with the fully qualified class name of the record each new record class will extend. Default is **\\LeanOrm\\Model\\Record**
- **{{{CREATED\_TIMESTAMP\_COLUMN\_NAME}}}** will be substituted with NULL or name of the db column that will be timestamped each time a new record is inserted into the db
- **{{{UPDATED\_TIMESTAMP\_COLUMN\_NAME}}}** will be substituted with NULL or name of the db column that will be timestamped each time a record is saved to the db
- **{{{DB\_COLS\_AS\_PHP\_CLASS\_PROPERTIES}}}** will be substituted with a partial docblock of db field names for a Record
- **{{{NAME\_SPACE}}}** will be subsituted with an empty string or a specified namespace name with **\\{{{MODEL\_OR\_COLLECTION\_CLASS\_NAME\_PREFIX}}}** appended to it
- **{{{MODEL\_OR\_COLLECTION\_CLASS\_NAME\_PREFIX}}}** will be subsituted with a pluralized camel-cased version of **{{{TABLE\_NAME}}}**
- **{{{RECORD\_CLASS\_NAME\_PREFIX}}}** will be subsituted with a singularized camel-cased version of **{{{TABLE\_NAME}}}**
- **{{{PRIMARY\_COL\_NAME}}}** will be subsituted with an empty string or the name of the primary key column in the table **{{{TABLE\_NAME}}}**
- **{{{TABLE\_NAME}}}** will be subsituted with the name of the db table that we are generating collection, model &amp; record classes for
- **{{{METADATA\_ARRAY}}}** will be subsituted with an array containing table col metadata which will be included in model constructors if the config entry **store\_table\_col\_metadata\_array\_in\_file** has a value of **true**
- **{{{INCLUDE\_TABLE\_COL\_METADATA}}}** will be subsituted with an include statement (including the metadata array) in the model classes' constructors if the config entry **store\_table\_col\_metadata\_array\_in\_file** has a value of **true**

Contributing
------------

[](#contributing)

### Running Tests

[](#running-tests)

To run the tests in this package, just run the command below:

> composer test

By default, the tests run against an in-memory sqlite database using PDO.

To change the tests to run against another database engine such as mysql, run the command below:

> composer gen-test-pdo-config

Then go and edit **./tests/pdo.php** with the PDO arguments for the database you want to connect to.

Note that you only need to point to a database that has been created. You don't have to create the tables and views needed for testing, they will automatically be created when the test suite is run. In fact make sure there are no views or tables in the configured database. Also make sure the username you specified (for non-sqlite DBs) has permission to create and drop tables and view.

Because of the way the test-suite is designed, in-memory sqlite does not work. The sqlite db must be stored in a file. This is already setup in the default pdo config.

The package should work with MS Sqlserver, but the tests will only run with sqlite, mysql &amp; postgres databases.

### Branching

[](#branching)

These are the branches in this repository:

- **main:** contains code for the latest major version of this package
- **3.x:** contains code for the **3.x** version of this package
- **2.x:** contains code for the **2.x** version of this package
- **1.x:** contains code for the **1.x** version of this package

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance92

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity68

Established project with proven stability

 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 ~56 days

Recently: every ~120 days

Total

23

Last Release

40d ago

Major Versions

1.0.11 → 2.0.02024-03-13

1.x-dev → 3.0.02024-12-06

3.x-dev → 4.0.02026-05-08

PHP version history (3 changes)1.0.0PHP &gt;=7.4.0

2.0.0PHP &gt;=8.1.0

4.0.0PHP &gt;=8.2.0

### Community

Maintainers

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

---

Top Contributors

[![rotexdegba](https://avatars.githubusercontent.com/u/1242622?v=4)](https://github.com/rotexdegba "rotexdegba (17 commits)")

---

Tags

datadatabaseormmysqlsqlitepostgresqlsqlpdodbgatewaytableleantable data gatewaylean ormlean databaselean db

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rotexsoft-leanorm-cli/health.svg)

```
[![Health](https://phpackages.com/badges/rotexsoft-leanorm-cli/health.svg)](https://phpackages.com/packages/rotexsoft-leanorm-cli)
```

###  Alternatives

[aura/sqlquery

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

4563.1M37](/packages/aura-sqlquery)[cycle/database

DBAL, schema introspection, migration and pagination

65746.2k48](/packages/cycle-database)[atlas/query

Object-oriented query builders and performers for MySQL, Postgres, SQLite, and SQLServer.

41253.7k7](/packages/atlas-query)[aura/sqlschema

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

41240.2k4](/packages/aura-sqlschema)[delight-im/db

Safe and convenient SQL database access in a driver-agnostic way

47165.7k7](/packages/delight-im-db)[tommyknocker/pdo-database-class

Framework-agnostic PHP database library with unified API for MySQL, MariaDB, PostgreSQL, SQLite, MSSQL, and Oracle. Query Builder, caching, sharding, window functions, CTEs, JSON, migrations, ActiveRecord, CLI tools, AI-powered analysis. Zero external dependencies.

816.0k](/packages/tommyknocker-pdo-database-class)

PHPackages © 2026

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