In order to be able to query SQL databases (eg: MySQL), you first need to open bootstrap index.php file add this event listener to Lucinda\STDOUT\FrontController object:
$object->addEventListener(Lucinda\STDOUT\EventType::APPLICATION, Lucinda\Project\EventListeners\NoSQLDataSource::class);
and / or to Lucinda\ConsoleSTDOUT\FrontController object:
$object->addEventListener(Lucinda\ConsoleSTDOUT\EventType::APPLICATION, Lucinda\Project\EventListeners\Console\NoSQLDataSource::class);
then create in stdout.xml a <server> tag (which will hold your connection settings), child of DEVELOPMENT ENVIRONMENT tag (because credentials will be different on another environment), child of <nosql> tag. Example:
<nosql>
<local>
<server driver="redis" host="localhost"/>
</local>
</sql>
If your site uses multiple database servers for a single DEVELOPMENT ENVIRONMENT, it is allowed to have multiple <server> entries there. To learn more how to configure this tag and drivers supported, check official documentation!
Querying NoSQL databases requires you completed setting NoSQL databases section!
To retrieve a connection for a DEVELOPMENT ENVIRONMENT, use this instead:
$driver = Lucinda\NoSQL\ConnectionFactory::getInstance(SERVER_NAME);
Where SERVER_NAME is value of "name" attribute at matching <server> tag. If no such attribute was defined, empty string is assumed!
This will return a single Lucinda\NoSQL\Driver per session, reused until script ends and automatically closed afterwards (unless driver is apc/apcu, requiring no connections).
Alternatively you can use NoSQL function framework already comes with::
$driver = NoSQL(SERVER_NAME = "");
Once a connection is retrieved, you can run basic document database logic such as:
$driver->set(KEY, VALUE, EXPIRATION);
Example:
// saves a key named "foo" with value "bar" in DB that expires in 10 seconds
$driver->set("foo", "bar", 10);
// retrieves value of "foo" from DB
$x = $driver->get("foo");
This works the same way as PDO, hiding complexities of driver used. If, however, basic operations are not enough and you need to work with actual vendor logic use:
$vendorDriver = $driver->getDriver();
then use vendor official documentation (eg: redis) to query that object.
When framework is installed, a number of DAO classes are pushed already to your project, all assuming you will only use one NoSQL driver per DEVELOPMENT ENVIRONMENT. If that is not true for your project, modify DRIVER_NAME constant appropriately in following files:
Value of DRIVER_NAME must match with value of a "name" attribute in a <server> tag for that DEVELOPMENT ENVIRONMENT!