spiral-modules / database

Database Abstraction Layer, Schema Introspection, Schema Generation, Query Builders
MIT License
53 stars 19 forks source link

Allow to use any injection name if there is only 1 database #75

Open vladgorenkin opened 3 years ago

vladgorenkin commented 3 years ago

It'd be great if we could use db or database (or any other name) as argument names if there is only one database declared. Currently you have to use default database name as an injection argument:

// database config
return [
    'default' => 'default',
   'databases' => [
        'default' => [
            'driver' => 'postgres',
        ],
   ],
   ...
]

// some service
public function __construct(private DatabaseInterface $default) {}

private DatabaseInterface $db would throw an exception: db preset was not found.

wolfy-j commented 3 years ago

Interesting sugar addition. Thank you