PHPackages                             flytachi/db-mapping - 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. flytachi/db-mapping

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

flytachi/db-mapping
===================

Database Mapping

1.2.8(9mo ago)2610↓67.9%1MITPHPPHP &gt;=8.3

Since Jul 2Pushed 9mo agoCompare

[ Source](https://github.com/Flytachi/db-mapping)[ Packagist](https://packagist.org/packages/flytachi/db-mapping)[ RSS](/packages/flytachi-db-mapping/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (1)Versions (18)Used By (1)

DB Mapping Library
==================

[](#db-mapping-library)

Overview
--------

[](#overview)

This library provides a robust and flexible solution for mapping PHP classes and their properties to database schemas. It leverages PHP 8 attributes to define database table structures, column types, constraints, and relationships directly within your model classes. This approach reduces boilerplate code, improves maintainability, and ensures a clear, declarative definition of your database schema.

Features
--------

[](#features)

- **Attribute-based Schema Definition**: Define database tables, columns, and constraints using PHP 8 attributes.
- **Support for Various Data Types**: Comprehensive support for common SQL data types, including integers, strings, booleans, dates, and more.
- **Indexing and Constraints**: Easily define primary keys, unique keys, and foreign key constraints.
- **Extensible Architecture**: Designed for easy extension to support custom attributes and database dialects.
- **SQL Generation**: Automatically generates SQL DDL (Data Definition Language) statements based on your class definitions.

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

[](#installation)

To install the DB Mapping Library, you can use Composer:

```
composer require flytachi/db-mapping
```

Usage
-----

[](#usage)

### Defining a Table

[](#defining-a-table)

To define a database table, you can use the `#[Table]` attribute on your PHP class. Each property in the class can then be annotated with various attributes to define its corresponding database column.

```
