nadyita / reactdb
A wrapper around MySQL and SQLite to have common interfaces
Requires
- php: >=7.3.0
- clue/reactphp-sqlite: ^1.0.1
- react/event-loop: ^1.1
- react/mysql: ^0.5.4
Requires (Dev)
- phpunit/phpunit: ^8
This package is not auto-updated.
Last update: 2025-01-03 08:43:17 UTC
README
A wrapper around ReactPHP's MySQL and SQLite implementations that wraps them in a unified interface, so that you don't have to worry about which database implementation you are actually talking to.
Quickstart example
Here is an SQLite database connection using this interface
$loop = React\EventLoop\Factory::create(); $factory = new Clue\React\SQLite\Factory($loop); $db = new Nadyita\ReactDB\SQLite($factory->openLazy('test.db')); $db->exec('CREATE TABLE IF NOT EXISTS foo (id INTEGER PRIMARY KEY AUTOINCREMENT, bar STRING)'); $name = 'Alice'; $db->query('INSERT INTO foo (bar) VALUES (?)', [$name])->then( function (Nadyita\ReactDB\Result $result) use ($name) { echo 'New ID for ' . $name . ': ' . $result->getinsertID() . PHP_EOL; } ); $db->quit(); $loop->run();
Install
The recommended way to install this library is through Composer. New to Composer?
This project follows SemVer. This will install the latest supported version:
$ composer require nadyita/reactdb:^1.0
See also the CHANGELOG for details about version upgrades.
This project aims to run on any platform and thus does not require any PHP extensions and supports running on PHP 7.3+.
Tests
To run the test suite, you first need to clone this repo and then install all dependencies through Composer:
$ composer install
To run the test suite, go to the project root and run:
$ composer test
License
MIT, see LICENSE file.