limoncello-php / app

Quick start JSON API application
MIT License
83 stars 7 forks source link

Does limoncello support NoSQL, like mongoDB? #59

Closed dreamsbond closed 5 years ago

dreamsbond commented 5 years ago

Curious if limoncello supports mongoDB.

neomerx commented 5 years ago

Limoncello uses DBAL to work with databases. A list of supported databases by DBAL is here. Thus, if you have MongoDB installed you can either use it directly or with a wrapper such as Doctrine MongoDB.

Technically, it would be better to place either of them to the application container as shown here and use it anywhere in the app.

For example,

class MongoDbConfigurator implements ContainerConfiguratorInterface
{
    public static function configureContainer(LimoncelloContainerInterface $container): void
    {
        $container[\MongoDB\Driver\Manager::class] = function (PsrContainerInterface $container) {
            // read MongoDB settings (e.g. connect string and etc)
            $settings = $container->get(SettingsProviderInterface::class)->get(\Settings\MongoDB::class);

            // create MongoDB connection with settings
            return new \MongoDB\Driver\Manager(...);
        };
    }
}
dreamsbond commented 5 years ago

Thanks!