PHPackages                             kfirba/import-query-generator - 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. kfirba/import-query-generator

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

kfirba/import-query-generator
=============================

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

v1.0(8y ago)3574.1k↑35%9[1 issues](https://github.com/kfirba/import-query-generator/issues)MITPHPCI failing

Since Jan 12Pushed 5y ago1 watchersCompare

[ Source](https://github.com/kfirba/import-query-generator)[ Packagist](https://packagist.org/packages/kfirba/import-query-generator)[ RSS](/packages/kfirba-import-query-generator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)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 MySQL's `ON DUPLICATE KEY UPDATE` feature.

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 kfirba/import-query-generator
```

Usage
-----

[](#usage)

```
use Kfirba\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

38

—

LowBetter than 85% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community13

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 85.7% 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

Unknown

Total

1

Last Release

3048d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/00b97262a98fa4f5375e21a881c2b43493f4fd60067cea73669365fe60da4c79?d=identicon)[kfirba](/maintainers/kfirba)

---

Top Contributors

[![kfirba](https://avatars.githubusercontent.com/u/8510486?v=4)](https://github.com/kfirba "kfirba (6 commits)")[![dineshsailor](https://avatars.githubusercontent.com/u/31342733?v=4)](https://github.com/dineshsailor "dineshsailor (1 commits)")

---

Tags

create-or-updateimportmysqlsql-generationsql-query

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  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)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

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

Reliese Components for Laravel Framework code generation.

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

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

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