PHPackages                             aymanelarian/import-query-generator-pg - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. aymanelarian/import-query-generator-pg

ActiveLibrary[Database &amp; ORM](/categories/database)

aymanelarian/import-query-generator-pg
======================================

An efficient Postgres query generator for mass resource import, distinguishing between new records and records to update.

v1.3(5y ago)07MITPHPCI failing

Since Jul 25Pushed 5y agoCompare

[ Source](https://github.com/AymanElarian/import-query-generator-pg)[ Packagist](https://packagist.org/packages/aymanelarian/import-query-generator-pg)[ RSS](/packages/aymanelarian-import-query-generator-pg/feed)WikiDiscussions master Synced yesterday

READMEChangelog (3)Dependencies (1)Versions (6)Used By (0)

Import Query Generator
======================

[](#import-query-generator)

An efficient query generator for mass resource import, **distinguishing between new records and records to update**. This library uses Postgree's `ON CONFLICT DO UPDATE` feature.

its forked from [kfirba/import-query-generator](https://github.com/kfirba/import-query-generator) and adjusted for postgree sql.

Preface
-------

[](#preface)

I highly recommend you at least skim through [my blog about this library](https://kfirba.me/blog/performant-mass-update-or-create-strategy-for-data-imports) to get a better understanding of this library.

Installation
------------

[](#installation)

You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):

```
composer require AymanElarian/import-query-generator-pg
```

Usage
-----

[](#usage)

```
use AymanElarian\QueryGenerator;

$table = 'users';
$data = [
    ['name' => 'John', 'email' => 'john@example.com', 'password' => 'hashed_password', 'created_at' => date('Y-m-d'), 'updated_at' => date('Y-m-d')],
    ['name' => 'Jane', 'email' => 'jane@example.com', 'password' => 'hashed_password', 'created_at' => date('Y-m-d'), 'updated_at' => date('Y-m-d')],
    ['name' => 'Susy', 'email' => 'susy@example.com', 'password' => 'hashed_password', 'created_at' => date('Y-m-d'), 'updated_at' => date('Y-m-d')],
];
$excludedColumnsFromUpdate = ['password', 'created_at'];

$queryObject = (new QueryGenerator)->generate($table, $data, $excludedColumnsFromUpdate);

$queryObject->getQuery();
// -> "insert into `users` (`name`,`email`,`password`,`created_at`,`updated_at`) values (?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?) on duplicate key update `name`=VALUES(`name`),`email`=VALUES(`email`),`updated_at`=VALUES(`updated_at`)"

$queryObject->getBindings();
// -> ['John', 'john@example.com', 'hashed_password', '2018-01-12', '2018-01-12', 'Jane', 'jane@example.com', 'hashed_password', '2018-01-12', '2018-01-12', 'Susy', 'Susy@example.com', 'hashed_password', '2018-01-12', '2018-01-12']
```

As you may have noticed, the generator defaults to `column=VALUES(column)` since this is usually what we use when we attempt to bulk import some data. Need another behavior? You can submit a PR or just [open an issue](https://github.com/kfirba/import-query-generator/issues/new) and we can talk about it 🤓.

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 61.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

2117d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e0f82df6451f596356b919f4ec031b0b766344dbfc875a15d918d4565e3f70b6?d=identicon)[AymanElarian](/maintainers/AymanElarian)

---

Top Contributors

[![AymanElarian](https://avatars.githubusercontent.com/u/364872?v=4)](https://github.com/AymanElarian "AymanElarian (8 commits)")[![kfirba](https://avatars.githubusercontent.com/u/8510486?v=4)](https://github.com/kfirba "kfirba (5 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/aymanelarian-import-query-generator-pg/health.svg)

```
[![Health](https://phpackages.com/badges/aymanelarian-import-query-generator-pg/health.svg)](https://phpackages.com/packages/aymanelarian-import-query-generator-pg)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
