Method createFromFillable refactored for more databases support #51
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
createFromFillable
method refactored to support the databases provided by the laravel framework.As the method initially made use of DB::select, using the SQL
describe table_name
, but describe is not supported by PostgreSQL for example so I decided to use Facade Schema'sgetDoctrineColumn
method.getDoctrineColumn
method returns the instance of\Doctrine\DBAL\Schema\Column
class.Couple of methods from \Doctrine\DBAL\Schema\Column class:
The method that interests us is the
getType
, but in the future if we need to check if a certain column is nullable or for example its size, we will have this flexibility.In this way, all information about the column is retrieved with:
And column type checks, we can easily retrieve as follows:
Therefore, the column type checks, where we actually formatted and assembled the livewire powergrid component, looked like this
To test the changes made, I created a repository with code for a demo laravel application. This repository can be found at URL
https://github.com/vs0uz4/powergrid-demo
.For information, the migration code that creates the table used in the tests is shown below
And by way of comparison, the values referring to the types of columns returned using the
describe
SQL sentence or using thegetDoctrineColumn()
method are displayed in the table below.As the demo application uses
Laravel Sail
and it does not support the Microsoft database, it was not possible to reproduce the tests in this environment.For information, follow the structures of the
category
table in the tested databases.MySQL
PostgreSQL
SQLite
Result is!