thecodingmachine/tdbm-fluid-schema-builder

使用流畅语法构建和修改TDBM使用的数据库模式。

v2.0.0 2024-01-28 13:39 UTC

This package is auto-updated.

Last update: 2024-08-28 15:06:32 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License Scrutinizer Code Quality Build Status Coverage Status

TDBM流畅模式构建器

使用DBAL和流畅语法构建和修改数据库模式。此项目允许您定制数据库模式以符合TDBM(它将允许您轻松添加TDBM可以读取的注解)。

它是dbal-fluid-schema-builder的超集。

如果您不了解dbal-fluid-schema-builder,请先查看文档

为什么?

TDBM可以读取模式注释中的一系列注解(请参阅TDBM注解文档)。

此库允许使用添加到"dbal-fluid-schema-builder"的函数编写这些注解。

增加了什么?

$db = new TdbmFluidSchema($schema);

// Customize the name of the Bean class
$posts = $db->table('posts')->customBeanName('Article');

// You can pass a new 'v1' or 'v4' parameter to uuid().
// This will generate a @UUID TDBM annotation that will help TDBM autogenerate the UUID 
$posts = $db->table('posts')->uuid('v4');

// Customize the visibility of a column
$db->table('posts')
   ->column('user_id')->references('users')
                      ->protectedGetter() // The Post.getUser() method is protected
                      ->protectedSetter() // The Post.setUser() method is protected
                      ->protectedOneToMany() // The User.getPosts() method is protected

// Customize implemented interfaces
$db->table('posts')
   ->implementsInterface('App\\PostInterface')  // The generated bean will implement interface App\\PostInterface
   ->implementsInterfaceOnDao('App\\PostDaoInterface'); // The generated DAO will implement interface App\\PostDaoInterface

// The "posts" table will generate a GraphQL type (i.e. the bean will be annotated with the GraphQLite @Type annotation).
$posts = $db->table('posts')->graphqlType();

// You can pass a new 'v1' or 'v4' parameter to uuid().
// This will generate a @UUID TDBM annotation that will help TDBM autogenerate the UUID 
$posts = $db->table('posts')->column('title')->string(50)->graphqlField() // The column is a GraphQL field
            ->fieldName('the_title') // Let's set the name of the field to a different value 
            ->logged() // The user must be logged to view the field
            ->right('CAN_EDIT') // The user must have the 'CAN_EDIT' right to view the field
            ->failWith(null) // If the user is not logged or has no right, let's serve 'null'
            ->endGraphql();

// You can pass instructions on how JSON serialization occurs.
// This will generate a set of JSONxxx annotations.
$nodes = $db->table('nodes')
    ->column('id')->integer()->primaryKey()->autoIncrement()->jsonSerialize()->ignore()
    ->column('alias_id')->references('nodes')->null()->jsonSerialize()->recursive()
    ->column('parent_id')->references('nodes')->null()->jsonSerialize()->include()
    ->column('root_id')->references('nodes')->null()->jsonSerialize()->ignore()
    ->column('owner_id')->references('authors')->null()->jsonSerialize()->formatUsingProperty('name')->include()
    ->column('owner_country')->references('authors')->null()->jsonSerialize()->formatUsingMethod('getCountryName')->include()
    ->column('name')->string()->jsonSerialize()->key('basename')
    ->column('size')->integer()->notNull()->default(0)->jsonSerialize()->numericFormat(null, null, null, ' o')
    ->column('weight')->float()->null()->jsonSerialize()->numericFormat(2, ',', '.', 'g')
    ->column('created_at')->date()->null()->jsonSerialize()->datetimeFormat("Y-m-d")
    ->column('another_parent')->references('nodes')->comment('@JsonCollection("entries") @JsonFormat(property="entry")');

$db->junctionTable('posts', 'users')->graphqlField(); // Expose the many-to-many relationship as a GraphQL field.