PHPackages                             psx/sql - 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. psx/sql

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

psx/sql
=======

Generate type-safe PHP classes from your database

v4.4.2(2mo ago)1773.4k↓35.7%14Apache-2.0PHPPHP &gt;=8.1CI passing

Since Apr 2Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/apioo/psx-sql)[ Packagist](https://packagist.org/packages/psx/sql)[ Docs](https://phpsx.org)[ Fund](https://www.paypal.me/fusioapi)[ GitHub Sponsors](https://github.com/chriskapp)[ RSS](/packages/psx-sql/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (16)Versions (66)Used By (4)

SQL
===

[](#sql)

This library generates type-safe PHP classes from your database tables and thus allows you to interact with your database in a complete type-safe way.

In traditional ORMs you write a class add specific metadata and generate based on this class your tables, this means our source code defines how a table should look. This library thinks the other way around (database first), this means you first build your database schema i.e. through a tool like doctrine migrations and then you can use this library to automatically generate all repository and model classes based on the table schema. This has the great advantage that we can generate completely typed repositories. We automatically generate a class for each row (entity) and a repository which accepts this row. This concept is not new and the Java world has i.e. jOOQ which also follows this idea. It of course means also that you need to regenerate your classes if you change your schema.

Generate
--------

[](#generate)

To generate the table and row classes you can either integrate the `PSX\Command\GenerateCommand` into your Symfony console app or you can also do this programmatically through the `PSX\Sql\Generator` class s.

```
