Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

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

License

NotificationsYou must be signed in to change notification settings

kfirba/import-query-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

An efficient query generator for mass resource import,distinguishing between new records and records to update. This library uses MySQL'sON DUPLICATE KEY UPDATE feature.

Preface

I highly recommend you at least skim throughmy blog about this library to get a better understanding of this library.

Installation

You can add this library as a local, per-project dependency to your project usingComposer:

composer require kfirba/import-query-generator

Usage

useKfirba\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 = (newQueryGenerator)->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 tocolumn=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 justopen an issue and we can talk about it 🤓.

License

This package is open-sourced software licensed under theMIT license.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp