laravel-test-factory-helper
laravel-test-factory-helper copied to clipboard
PostgreSQL query fix
If the application is connected to an postgres DB then the query that existed wouldn't suffice, because postgres has a different syntax. I added a simple if clause to check if the laravel application is connected to an postgres DB, if so the query will be executed with proper postgres syntax else the existing query will be executed. This will remove the SQL error as well as the class not recognized error when running the php artisan command for applications that have postgres DB.
Thanks. I'd like to leverage Doctrine. I believe it's already a dependency of the project and handles all this "what type of DB" is it logic for free.
I'm going to leave this open for a bit. In the meantime, anyone landing here can feel free to pull this branch.
What if the user has custom connection names?
I think the best way would be to add a option to the command, to pass the desired connection name if not default:
protected $name = 'generate:model-factory {--connection=?}';
Than, it should query for the connection driver if the option is set:
$connection = $this->option('connection');
$dbDriver = config("database.connections.$connection.driver");
if ($dbDriver === 'pgsql') {
Something like that, give or take.
Even in case of custom connection name that probably still will be a default connection. It would be best to just check the connection driver, not a name.
Something like that should work fine:
if (DB::connection()->getDriverName() === 'pgsql') {
Any plan on merging this?