https://github.com/thecodingmachine/tdbm-fluid-schema-builder
Build and modify your database schema used by TDBM using a fluid syntax.
https://github.com/thecodingmachine/tdbm-fluid-schema-builder
Last synced: about 1 year ago
JSON representation
Build and modify your database schema used by TDBM using a fluid syntax.
- Host: GitHub
- URL: https://github.com/thecodingmachine/tdbm-fluid-schema-builder
- Owner: thecodingmachine
- Created: 2019-03-11T10:37:39.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-01-28T13:40:41.000Z (over 2 years ago)
- Last Synced: 2025-04-09T20:15:38.692Z (about 1 year ago)
- Language: PHP
- Size: 49.8 KB
- Stars: 0
- Watchers: 7
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://packagist.org/packages/thecodingmachine/tdbm-fluid-schema-builder)
[](https://packagist.org/packages/thecodingmachine/tdbm-fluid-schema-builder)
[](https://packagist.org/packages/thecodingmachine/tdbm-fluid-schema-builder)
[](https://packagist.org/packages/thecodingmachine/tdbm-fluid-schema-builder)
[](https://scrutinizer-ci.com/g/thecodingmachine/tdbm-fluid-schema-builder/?branch=master)
[](https://travis-ci.org/thecodingmachine/tdbm-fluid-schema-builder)
[](https://coveralls.io/github/thecodingmachine/tdbm-fluid-schema-builder?branch=master)
# Fluid schema builder for TDBM
Build and modify your database schema using [DBAL](http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/schema-representation.html) and a fluid syntax.
This project allows you to tailor your database schema to TDBM (it will allow you to easily add annotations that TDBM can read).
It is a super-set of [dbal-fluid-schema-builder](https://github.com/thecodingmachine/dbal-fluid-schema-builder/).
If you don't know *dbal-fluid-schema-builder*, [check the documentation first](https://github.com/thecodingmachine/dbal-fluid-schema-builder/).
## Why?
TDBM can read a number of annotations in the schema comments (see [TDBM annotations documentation](https://thecodingmachine.github.io/tdbm/doc/annotations.html)).
This library allows to write these annotations using functions added to the "dbal-fluid-schema-builder".
## What's added?
```php
$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.
```