🔌 A Doctrine DBAL Driver implementation on top of Swoole Coroutine PostgreSQL extension

Overview

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.

You might also like...
PHP Object Model Manager for Postgresql

POMM: The PHP Object Model Manager for Postgresql Note This is the 1,x version of Pomm. This package is not maintained anymore, the stable Pomm 2.0 is

Support for many missing PostgreSQL specific features
Support for many missing PostgreSQL specific features

Laravel supports many different databases and therefore has to limit itself to the lowest common denominator of all databases. PostgreSQL, however, of

phpMyFAQ - Open Source FAQ web application for PHP and MySQL, PostgreSQL and other databases

phpMyFAQ 3.1 What is phpMyFAQ? phpMyFAQ is a multilingual, completely database-driven FAQ-system. It supports various databases to store all data, PHP

Orm is a simple database abstraction layer that supports postgresql.

Orm What is it Orm is a simple database abstraction layer that supports postgresql. Welcome to join us or star us for encouragement. Requires php 8.1

Doctrine Object Relational Mapper (ORM)

3.0.x 2.9.x 2.8.x Doctrine 2 is an object-relational mapper (ORM) for PHP 7.1+ that provides transparent persistence for PHP objects. It sits on top o

Doctrine Database Abstraction Layer

Doctrine DBAL 4.0-dev 3.0 2.13 N/A N/A Powerful database abstraction layer with many features for database schema introspection, schema management and

Psalm Stubs for doctrine/mongodb-odm library

doctrine-mongodb-psalm-plugin A Doctrine plugin for Psalm (requires Psalm v4). Installation: $ composer require --dev runtothefather/doctrine-mongodb-

Provides integration for Doctrine with various Symfony components.

Doctrine Bridge The Doctrine bridge provides integration for Doctrine with various Symfony components. Resources Contributing Report issues and send P

Monadic Doctrine repositories helper classes and services.

Doctrine Repository Monadic Helper Description This project provides the necessary classes and services to use Doctrine repositories in a more functio

Comments
  • Bug Fixes

    Bug Fixes

    This pull request fixes the following bug :

    1. Current implementation of fetchAllAssociative() and fetchAllNumeric() were causing memory leaks , its been replaced by swoole-postgres's PostgreSQL->fetchAll(...) method

    2. fetchAllAssociative() , fetchAllNumeric() , fechOne() did not work properly when there was no results , fetchOne() causes 'trying to get index of a boolean' and fetchAllAssociative() , fetchAllNumeric() caused boolean to be returned . which have been fixed to return empty array

    bug 
    opened by ipranjal 2
  • chore(deps): bump doctrine/dbal from 3.1.3 to 3.3.1

    chore(deps): bump doctrine/dbal from 3.1.3 to 3.3.1

    Bumps doctrine/dbal from 3.1.3 to 3.3.1.

    Release notes

    Sourced from doctrine/dbal's releases.

    3.3.1

    Release 3.3.1

    3.3.1

    • Total issues resolved: 2
    • Total pull requests resolved: 7
    • Total contributors: 6

    Bugfixes

    Documentation

    Internal

    3.3.0

    Release 3.3.0

    3.3.0

    • Total issues resolved: 2
    • Total pull requests resolved: 27
    • Total contributors: 6

    Static Analysis

    ... (truncated)

    Commits
    • 5b6eb6c Merge pull request #5220 from greg0ire/platform-aware-comparison-through-comp...
    • 1898f74 Allow dynamic call to compareSchemas
    • 9ddb464 Merge pull request #5211 from greg0ire/drop-pg-93-check
    • b5e56ae Drop requirement for PostgreSQL 9.4+
    • e973fbe Merge pull request #5202 from morozov/issues/5195
    • f5a111e Merge pull request #5197 from javiereguiluz/patch-2
    • 0ed09e1 Optimize AbstractMySQLPlatform::getListTableForeignKeysSQL()
    • 16e8d15 Merge pull request #5201 from greg0ire/loosen-column-comparison
    • 2b83a4e Merge pull request #5196 from morozov/issues/5130
    • 68f5935 Warn against relying on DC2Type comments.
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Swoole dependency issue

    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

    enhancement 
    opened by ipranjal 0
Owner
Leo Cavalcante
PHP Software Engineer @PicPay & @swoole Evangelist
Leo Cavalcante
PostgreSQL enhancements for Doctrine

PostgreSQL enhancements for Doctrine. Provides support for advanced data types (json, jssnb, arrays), text search, array operators and jsonb specific functions.

Martin Georgiev 258 Dec 31, 2022
A simple library to access and manipulate database records. Built on top of Dibi and hardwired for PostgreSQL.

grifart/tables A simple library to access and manipulate database records. Built on top of Dibi and hardwired for PostgreSQL. This library is develope

GRIFART 5 Nov 11, 2022
Laravel Thermite is an extended PostgreSQL Laravel database driver to connect to a CockroachDB cluster.

Laravel Thermite Laravel Thermite is an extended PostgreSQL Laravel database driver to connect to a CockroachDB cluster. ?? Supporting If you are usin

Renoki Co. 9 Nov 15, 2022
Spot v2.x DataMapper built on top of Doctrine's Database Abstraction Layer

Spot DataMapper ORM v2.0 Spot v2.x is built on the Doctrine DBAL, and targets PHP 5.4+. The aim of Spot is to be a lightweight DataMapper alternative

Spot ORM 602 Dec 27, 2022
Doctrine PHP mapping driver

WORK IN PROGRESS! Doctrine PHP mapping driver Alternative mapping driver that allows to write mappings in PHP. Documentation Associations examples TOD

Andrey Klimenko 3 Aug 15, 2021
Поддержка очередей Redis (и на RabbitMq, и на Filesystem, и через DBAL) в Битриксе

Модуль для Битрикса, организующий работу с очередями через Redis (и не только) Поддерживаемый транспорт: Redis RabbitMq Filesystem DBAL Установка comp

Fedy 4 Aug 20, 2021
Doctrine extension to persist spatial data objects.

doctrine-Spatial Doctrine-spatial is a doctrine extension. It implements spatial types and functions. As exemple, this extension can help you to know

LongitudeOne 36 Jan 7, 2023
A drop-in Doctrine ORM 2 implementation for Laravel 5+ and Lumen

Laravel Doctrine ORM A drop-in Doctrine ORM 2 implementation for Laravel 5+ $scientist = new Scientist( 'Albert', 'Einstein' ); $scientist->a

Laravel Doctrine 777 Dec 17, 2022
Async Redis client implementation, built on top of ReactPHP.

clue/reactphp-redis Async Redis client implementation, built on top of ReactPHP. Redis is an open source, advanced, in-memory key-value database. It o

Christian Lück 240 Dec 20, 2022
Independent query builders for MySQL, PostgreSQL, SQLite, and Microsoft SQL Server.

Aura.SqlQuery Provides query builders for MySQL, Postgres, SQLite, and Microsoft SQL Server. These builders are independent of any particular database

Aura for PHP 424 Dec 12, 2022