Skip to content

asyncphp/icicle-database

Repository files navigation

Icicle Database

Build Status Code Quality Code Coverage Version License

Distributed, async DBAL, for Icicle applications.

What?

Synchronous architectures often use PDO to interact with databases. PDO does not provide ways to use it in asynchronous architectures, so this library uses a few tricks to allow PDO to execute transparently in separate processes.

Using Connectors

$factory = new ConnectorFactory();

$connector = $factory->create([
    "driver" => getenv("ICICLE_DRIVER"),
    "schema" => getenv("ICICLE_SCHEMA"),
    "username" => getenv("ICICLE_USERNAME"),
    "password" => getenv("ICICLE_PASSWORD"),
    "remit" => [
        "driver" => "zeromq",
        "server" => [
            "port" => getenv("ICICLE_REMIT_SERVER_PORT"),
        ],
        "client" => [
            "port" => getenv("ICICLE_REMIT_CLIENT_PORT"),
        ],
    ],
]);

yield $connector->query(
    "select * from pages"
);

Using Builders

$factory = new BuilderFactory();

$builder = $factory->create([
    "driver" => getenv("ICICLE_DRIVER"),
]);

$builder->table("pages")->select("*")->build();

Using Managers

$factory = new ManagerFactory();

$manager = $factory->create([
    "driver" => getenv("ICICLE_DRIVER"),
    "database" => getenv("ICICLE_DATABASE"),
    "username" => getenv("ICICLE_USERNAME"),
    "password" => getenv("ICICLE_PASSWORD"),
    "remit" => [
        "driver" => "zeromq",
        "server" => [
            "port" => getenv("ICICLE_REMIT_SERVER_PORT"),
        ],
        "client" => [
            "port" => getenv("ICICLE_REMIT_CLIENT_PORT"),
        ],
    ],
]);

yield $manager->table("pages")->select("*")->first();

Caveats

  • mysql, pgsql, sqlite, and sqlsrv are the only supported drivers
  • join, groupBy, having, orHaving, distinct methods are missing
  • Statements are executed in different processes to avoid blocking
  • Remit is used for inter-process communication

Versioning

This library follows Semver. According to Semver, you will be able to upgrade to any minor or patch version of this library without any breaking changes to the public API. Semver also requires that we clearly define the public API for this library.

All methods, with public visibility, are part of the public API. All other methods are not part of the public API. Where possible, we'll try to keep protected methods backwards-compatible in minor/patch versions, but if you're overriding methods then please test your work before upgrading.