PHPackages                             attreid/orm-structure - 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. attreid/orm-structure

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

attreid/orm-structure
=====================

Nextras/ORM Structure extension

3.0.0(7mo ago)062MITPHPPHP &gt;= 8.4

Since Aug 3Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/attreid/orm-structure)[ Packagist](https://packagist.org/packages/attreid/orm-structure)[ RSS](/packages/attreid-orm-structure/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (92)Used By (0)

Attreid ORM Structure
=====================

[](#attreid-orm-structure)

A powerful extension for Nextras ORM that provides automatic database structure management for MySQL databases. This library allows you to define database tables and views using PHP code, with automatic migration support and structure synchronization.

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

[](#table-of-contents)

- [Overview](#overview)
- [Installation](#installation)
- [Configuration](#configuration)
- [Architecture](#architecture)
- [Table Management](#table-management)
- [View Management](#view-management)
- [API Reference](#api-reference)
- [Migration Support](#migration-support)
- [Testing](#testing)
- [Development with Docker](#development-with-docker)
- [Best Practices](#best-practices)
- [Examples](#examples)

Overview
--------

[](#overview)

This library extends Nextras ORM with automatic database structure management capabilities. It allows you to:

- Define database tables using fluent PHP API
- Create database views with custom SQL queries
- Automatically manage database migrations
- Synchronize database structure with your code definitions
- Handle foreign key relationships and constraints
- Support for indexes, unique constraints, and full-text search

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

[](#installation)

```
composer require attreid/orm-structure
```

### Requirements

[](#requirements)

- PHP 8.4 or higher
- Nextras ORM 5.x
- Nette DI 3.x or 4.x
- MariaDB 10 database

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

[](#configuration)

Add the extension to your `config.neon`:

```
extensions:
    structure: Attreid\OrmStructure\DI\StructureExtension

structure:
    autoManageDb: true  # Automatically manage database structure on application startup
```

Architecture
------------

[](#architecture)

### Core Components

[](#core-components)

1. **Structure** - Main orchestrator class that manages all mappers and database operations
2. **TableMapper** - Abstract base class for defining database tables
3. **ViewMapper** - Abstract base class for defining database views
4. **Table** - Represents a database table with columns, indexes, and constraints
5. **View** - Represents a database view with custom SQL queries
6. **Column** - Represents individual table columns with type definitions

### Key Features

[](#key-features)

- **Automatic Structure Management**: Tables and views are automatically created/updated based on your mapper definitions
- **Migration Support**: Built-in migration system for handling schema changes
- **Type Safety**: Strongly typed column definitions with fluent API
- **Relationship Management**: Easy foreign key and many-to-many relationship handling
- **Index Management**: Support for various index types (unique, fulltext, regular)

Table Management
----------------

[](#table-management)

### Basic Table Definition

[](#basic-table-definition)

```
