GithubHelp home page GithubHelp logo

leocavalcante / swoole-postgresql-doctrine-driver Goto Github PK

View Code? Open in Web Editor NEW
23.0 5.0 7.0 71 KB

๐Ÿ”Œ A Doctrine DBAL Driver implementation on top of Swoole Coroutine PostgreSQL client

Home Page: https://wiki.swoole.com/#/coroutine_client/postgresql

License: MIT License

Dockerfile 4.25% PHP 95.75%
doctrine dbal driver swoole coroutine postgresql database orm async pool

swoole-postgresql-doctrine-driver's Introduction

Swoole Coroutine PostgreSQL Doctrine DBAL Driver

A Doctrine\DBAL\Driver implementation on top of Swoole\Coroutine\PostgreSQL.

Getting started

Install

composer require leocavalcante/swoole-postgresql-doctrine-driver

Usage

Doctrine parameters, for both DBAL and ORM projects, accepts the driverClass option; it is where we can inject this project's driver:

use Doctrine\DBAL\{Driver, DriverManager};

$params = [
    'dbname' => 'postgres',
    'user' => 'postgres',
    'password' => 'postgres',
    'host' => 'db',
    'driverClass' => Driver\Swoole\Coroutine\PostgreSQL\Driver::class,
    'poolSize' => 8,
];

$conn = DriverManager::getConnection($params);

Yes, I deliberately used the Doctrine\DBAL\Driver namespace + Swoole\Coroutine\PostgreSQL namespace, so it is not confusing.

You are ready to rock inside Coroutines (Fibers):

Co\run(static function() use ($conn): void {
    $results = [];
    $wg = new Co\WaitGroup();
    $start_time = time();

    Co::create(static function() use (&$results, $wg, $conn): void {
        $wg->add();
        $results[] = $conn->executeQuery('select 1, pg_sleep(1)')->fetchOne();
        $wg->done();
    });

    Co::create(static function() use (&$results, $wg, $conn): void {
        $wg->add();
        $results[] = $conn->executeQuery('select 1, pg_sleep(1)')->fetchOne();
        $wg->done();
    });

    $wg->wait();
    $elapsed = time() - $start_time;
    $sum = array_sum($results);

    echo "Two pg_sleep(1) queries in $elapsed second, returning: $sum\n";
});

You should be seeing Two pg_sleep(1) queries in 1 second, returning: 2 and the total time should not be 2 (the sum of pg_sleep(1)'s) because they ran concurrently.

real    0m1.228s
user    0m0.036s
sys     0m0.027s

Developing

Use Composer through Docker

docker-compose run --rm composer install
docker-compose run --rm composer test

It will build a development image with PHP, Swoole, Swoole's PostgreSQL extension and PCOV for coverage.

swoole-postgresql-doctrine-driver's People

Contributors

dependabot[bot] avatar ipranjal avatar leocavalcante avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

swoole-postgresql-doctrine-driver's Issues

Swoole dependency issue

If we are using ext-openswoole instead of ext-swoole composer does not allow this package to be installed

possible solutions :

  1. we can add both ext-openswoole and ext-swoole in the suggested section of composer rather than required

  2. We can check if swoole or openswoole exists during runtime

as composer currently does not support conditional dependencies

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.