定制 flytachi/db-mapping 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

flytachi/db-mapping

最新稳定版本:1.2.8

Composer 安装命令:

composer require flytachi/db-mapping

包简介

Database Mapping

README 文档

README

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

  • 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

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

composer require flytachi/db-mapping

Usage

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.

<?php

declare(strict_types=1);

namespace App\Models;

use Flytachi\DbMapping\Attributes\Entity\Table;
use Flytachi\DbMapping\Attributes\Hybrid\Id;
use Flytachi\DbMapping\Attributes\Primal\Varchar;
use Flytachi\DbMapping\Attributes\Primal\Integer;
use Flytachi\DbMapping\Attributes\Additive\DefaultVal;
use Flytachi\DbMapping\Attributes\Additive\NullableIs;

#[Table(name: "users")]
class User
{
    #[Id]
    #[Integer]
    public int $id;

    #[Varchar(length: 255)]
    public string $name;

    #[Varchar(length: 255)]
    #[NullableIs(true)]
    #[DefaultVal("guest@example.com")]
    public ?string $email;

    #[Integer]
    public int $age;
}

Generating SQL

You can use the library to generate SQL DDL statements from your defined classes. (Further examples will be provided in docs.md)

Contributing

Contributions are welcome! Please see CONTRIBUTING.md (if available) for details on how to contribute.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Generated by Manus AI

统计信息

  • 总下载量: 583
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-02