laravel-test-factory-helper icon indicating copy to clipboard operation
laravel-test-factory-helper copied to clipboard

PostgreSQL query fix

Open Chingoski opened this issue 4 years ago • 4 comments

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.

Chingoski avatar Mar 05 '20 12:03 Chingoski

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.

jasonmccreary avatar Mar 06 '20 04:03 jasonmccreary

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.

rmundel avatar Jun 18 '20 21:06 rmundel

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') {

TheDoctor0 avatar Jun 19 '20 09:06 TheDoctor0

Any plan on merging this?

AhmadWaleed avatar Jul 23 '20 11:07 AhmadWaleed