pavelvais / upsert-doctrine
Doctrine 更新和插入功能的助手
v0.2.1
2023-10-22 17:35 UTC
Requires
- php: >=8.0
- ext-mysqli: *
- doctrine/dbal: ^3.0
- doctrine/orm: ^2.0
Requires (Dev)
- doctrine/coding-standard: ^8.0 || ^9.0
- phpunit/phpunit: ^8.0 || ^9.0
README
Upsert-Doctrine 是一个 PHP 库,旨在为 Doctrine 提供优雅的上插操作解决方案。此库简化了在 Doctrine ORM 生态系统内单次操作中插入新记录或更新现有记录的过程。
安装
使用 Composer 安装 Upsert-Doctrine
composer require pavelvais/upsert-doctrine
使用方法
下面是一个基本示例,演示如何使用 Upsert-Doctrine
use PavelVais\UpsertDoctrine\UpsertManager; $entityManager = // ... get your Doctrine entity manager here $upsertManager = new UpsertManager($entityManager); // Example for Single Upsert $data = [ 'book_id' => 1, 'author_id' => 2, 'ownership_type' => 2, ]; $repositoryClass = DoctrineOrmEntity::class; // Replace with your actual repository class try { $result = $upsertManager->execute($data, $repositoryClass); // $result will contain the number of affected rows } catch (\Exception $e) { // Handle exceptions } // Example for Batch Upsert $batchData = [ [ 'book_id' => 1, 'author_id' => 2, 'ownership_type' => 2, ], [ 'book_id' => 2, 'author_id' => 3, 'ownership_type' => 1, ], ]; try { $result = $upsertManager->executeBatch($batchData, $repositoryClass); // $result will contain the number of affected rows } catch (\Exception $e) { // Handle exceptions }
使用 Docker 进行本地测试
此项目包含一个 Docker 设置,用于运行本地测试和开发。以下是开始步骤
-
构建和管理容器:在后台构建并启动容器。
make build
要停止和删除容器,请使用以下命令
make stop
-
安装依赖项:使用以下命令使用 Composer 安装项目依赖项
make composer-install
-
运行测试:运行 PHPUnit 测试以确保一切按预期工作。
make test
路线图
- 基本上插功能
- 批量上插方法
- 查询管理器
- 支持Postgres
- 实时数据库测试
贡献
欢迎贡献!对于重大更改,请首先提交一个问题来讨论您想更改的内容。确保更新必要的测试。
许可证
此项目受 MIT 许可证的许可 - 有关详细信息,请参阅 LICENSE 文件。