{"id":33993478,"url":"https://github.com/kfirba/import-query-generator","last_synced_at":"2025-12-13T07:21:46.707Z","repository":{"id":54143685,"uuid":"117213264","full_name":"kfirba/import-query-generator","owner":"kfirba","description":"An efficient query generator for mass resource import, distinguishing between new records and records to update.","archived":false,"fork":false,"pushed_at":"2021-03-08T06:53:02.000Z","size":12,"stargazers_count":35,"open_issues_count":1,"forks_count":9,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-24T06:22:01.339Z","etag":null,"topics":["create-or-update","import","mysql","sql-generation","sql-query"],"latest_commit_sha":null,"homepage":"https://kfirba.me/blog/performant-mass-update-or-create-strategy-for-data-imports","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kfirba.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-12T08:13:43.000Z","updated_at":"2025-05-29T15:32:23.000Z","dependencies_parsed_at":"2022-08-13T07:31:05.429Z","dependency_job_id":null,"html_url":"https://github.com/kfirba/import-query-generator","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/kfirba/import-query-generator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfirba%2Fimport-query-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfirba%2Fimport-query-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfirba%2Fimport-query-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfirba%2Fimport-query-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kfirba","download_url":"https://codeload.github.com/kfirba/import-query-generator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfirba%2Fimport-query-generator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27701952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-13T02:00:09.769Z","response_time":147,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["create-or-update","import","mysql","sql-generation","sql-query"],"created_at":"2025-12-13T07:21:46.206Z","updated_at":"2025-12-13T07:21:46.700Z","avatar_url":"https://github.com/kfirba.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Import Query Generator\n\nAn 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.\n\n## Preface\n\nI 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.\n\n##  Installation\n\nYou can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):\n\n```bash\ncomposer require kfirba/import-query-generator\n```\n\n## Usage\n\n```php\nuse Kfirba\\QueryGenerator;\n\n$table = 'users';\n$data = [\n    ['name' =\u003e 'John', 'email' =\u003e 'john@example.com', 'password' =\u003e 'hashed_password', 'created_at' =\u003e date('Y-m-d'), 'updated_at' =\u003e date('Y-m-d')],\n    ['name' =\u003e 'Jane', 'email' =\u003e 'jane@example.com', 'password' =\u003e 'hashed_password', 'created_at' =\u003e date('Y-m-d'), 'updated_at' =\u003e date('Y-m-d')],\n    ['name' =\u003e 'Susy', 'email' =\u003e 'susy@example.com', 'password' =\u003e 'hashed_password', 'created_at' =\u003e date('Y-m-d'), 'updated_at' =\u003e date('Y-m-d')],\n];\n$excludedColumnsFromUpdate = ['password', 'created_at'];\n\n$queryObject = (new QueryGenerator)-\u003egenerate($table, $data, $excludedColumnsFromUpdate);\n\n$queryObject-\u003egetQuery();\n// -\u003e \"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`)\"\n\n$queryObject-\u003egetBindings();\n// -\u003e ['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']\n```\n\nAs 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.\nNeed 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 🤓.\n\n## License\nThis package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkfirba%2Fimport-query-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkfirba%2Fimport-query-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkfirba%2Fimport-query-generator/lists"}