Bulk inserts and updates for Doctrine DBAL

1.x-dev 2021-10-06 07:27 UTC


PHP Version Tests


It provides bulk inserts and updates for Doctrine DBAL. To use it, create a BulkInsert object:

$bulkInsert = BulkInsert::create($dbalConnection);
    new BulkData([
        ['id' => 1, 'name' => 'Name One', 'description' => 'Description One'],
        ['id' => 2, 'name' => 'Name Two', 'description' => 'Description Two'],
        ['id' => 3, 'name' => 'Name Three', 'description' => 'Description Three'],

Currently, it supports only PostgreSQL, so if you need a different database platform, feel free to create a pull request to the repository or create BulkInsert object on your own:

$bulkInsert = new BulkInsert($dbalConnection, new YourQueryFactory());

For your implementation, you need to implement the QueryFactory interface. To make it easier for you, the default implementation of that interface (DbalQueryFactory) is not as final, so you can extend it and make some adjustments if needed.

Local test environment with docker

To execute integration tests for PostgreSQL you will need docker-compose. For a configuration, you can use prepared docker compose file to create your own docker-compose.yml. If you don't use port 5432, then the default configuration should work for you. If in your local environment the port is not available to use, then you can change it to a different one:

        image: postgres:11.3-alpine
        container_name: flow-test-db
            - YOUR_PORT:5432
            - POSTGRES_USER=postgres
            - POSTGRES_PASSWORD=postgres
            - POSTGRES_DB=postgres

Also, you need set this new port for PostgreSQL in PHPUnit configuration (phpunit.xml):

    <env name="PGSQL_DATABASE_URL" value="postgresql://postgres:postgres@" />

To start the docker container, just run: docker-compose up. Now, you are ready to execute the entire test suite:

composer test

For the code coverage, please install pcov.