6dreams/doctrine-bulk
最新稳定版本:2.0.0
Composer 安装命令:
composer require 6dreams/doctrine-bulk
包简介
Simple classes that allows bulk operations on doctrine entities.
README 文档
README
Adds ability to multiple insert of entities or array to database using doctrine schema.
Notes
- Designed for MySQL (also works with PostgreSQL)
- Works with custom id generators (need few tweaks)
- Without custom id generator, works only with MySQL AI
- Allows retrive first inserted id \ total updated
- As bonus this package includes
HashedIdGeneratorthat can be used for generate char(25) ids from entity data - Please note that UPDATE queries with HashedIdGenerator currently didn't support changing Id
Samples
Default usage
<?php declare(strict_types = 1); use \Doctrine\ORM\EntityManagerInterface; use \SixDreams\Bulk\BulkInsert; use \SixDreams\Bulk\BulkUpdate; /** * Class DbWrite */ class DbWrite { /** @var EntityManagerInterface */ private $manager; /** * Creates two users in one query. * * @return int */ public function createTwoUsers(): int { $firstInsertedId = (int) (new BulkInsert($this->manager, User::class)) ->addEntity(new User('user 1', 'password')) ->addEntity(new User('user 2', 'password')) ->execute(); return $firstInsertedId; } /** * Updates two users in database. */ public function updateTwoUsers(): void { (new BulkUpdate($this->manager, User::class)) ->addEntity(new User(1, 'user 1', 'new_user1_password')) ->addEntity(new User(2, 'user 1', 'new_user2_password'), ['password']) ->execute(); } }
统计信息
- 总下载量: 37.54k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 25
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-12-28