承接 nattreid/orm 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

nattreid/orm

Composer 安装命令:

composer require nattreid/orm

包简介

Extension Nextras/ORM

README 文档

README

Nastavení config.neon

extensions:
    dbal: Nextras\Dbal\Bridges\NetteDI\DbalExtension
    orm: NAttreid\Orm\DI\OrmExtension

dbal:
    dbal:
    driver: mysqli
    host: 127.0.0.1
    database: test
    username: test
    password: test

orm:
    model: App\Model\Orm
    useCamelCase: true
    autoManageDb: true # automaticka kontrola tabulek a vytvareni neexistujicich
    add:
        - Another\Orm

Model

namespace App\Model;

/**
 * @property-read ExampleRepository $example
 */
class Orm extends \Nextras\Orm\Model\Model {
    
}

Repository

class ExampleRepository extends \NAttreid\Orm\Repository {

    public static function getEntityClassNames() {
        return [Example::class];
    }
}

Mapper

class ExampleMapper extends \NAttreid\Orm\Mapper {

    protected function createTable(\NAttreid\Orm\Structure\Table $table) {
        $table->setDefaultDataFile(__DIR__.'/import.sql');
        
        $table->addPrimaryKey('id')
                ->int()
                ->setAutoIncrement();
        $table->addForeignKey('someId', SomeMapper::class);
        $table->addForeignKey('parentId', $table)
                ->setDefault(NULL);
        $table->addColumn('pa')
                ->varChar(20);
        $table->addColumn('allowed')
                ->boolean()
                ->setDefault(1)
                ->setKey();
        $table->addUnique('someId', 'parentId');
        $table->addFulltext('pa');

        $relationTable = $table->createRelationTable(OtherMapper::class);
        $relationTable->addForeignKey('exampleId', $table);
        $relationTable->addForeignKey('otherId', OtherMapper::class);
        $relationTable->setPrimaryKey('exampleId', 'otherId');

        // migrace 
        if (!$relationTable->exists) {
            $table->migration[] = function (Row $row, Connection $connection) use ($relationTable) {
                if (isset($row->oldColumnId)) {
                    $connection->query('INSERT INTO %table %values', $relationTable->name, [
                        'exampleId' => $row->id,
                        'otherId' => $row->oldColumnId
                    ]);
                }
            };
        }
        
        $this->onCreateTable[] = function () {
            $this->insert([
                [
                    'id' => 1,
                    'someId' => 1,
                    'parentId' => 1,
                    'pa' => 'test',
                    // ...
                ]
            ]);
        };
    }
}

Entity

/**
 * @property int $id {primary}
 * @property Some $some {m:1 Some, oneSided=true}
 * @property Example|NULL $parent {m:1 Example::$children}
 * @property OneHasMany|Example[] $children {1:m Example::$parent, orderBy=id}
 * @property string $pa
 * @property boolean $allowed {default TRUE}
 */
class Example extends \Nextras\Orm\Entity\Entity {

}

Dokumentace na adrese https://nextras.org/orm

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-03-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固