shredio/rapid-database-operations
Composer 安装命令:
composer require shredio/rapid-database-operations
包简介
README 文档
README
A PHP library for high-performance database operations with Doctrine ORM support.
Installation
composer require shredio/rapid-database-operations
Requirements
- PHP 8.3 or higher
- Doctrine ORM 3.0+ (optional, for Doctrine integration)
- Doctrine DBAL 4.0+ (optional, for Doctrine integration)
Features
- High-performance database operations - Optimized bulk insert and update operations
- Doctrine ORM integration - Seamless integration with Doctrine entities
- Multiple database platforms - Support for MySQL and SQLite
- Type-safe operations - Generic templates for type safety
- Symfony Bundle - Easy integration with Symfony applications
- Flexible escaping - Customizable value escaping strategies
Basic Usage
Using RapidOperationFactory
The RapidOperationFactory is the main entry point for creating database operations:
use Shredio\RapidDatabaseOperations\Doctrine\DoctrineRapidOperationFactory; $factory = new DoctrineRapidOperationFactory($entityManager);
Insert Operations
// Basic insert - fails on duplicate keys $inserter = $factory->createInsert(Article::class); $inserter->addRaw([ 'id' => 1, 'title' => 'Article Title', 'content' => 'Article content...' ]); $inserter->execute(); // Unique insert - silently ignores duplicates $uniqueInserter = $factory->createUniqueInsert(Article::class); $uniqueInserter->addRaw([ 'id' => 1, 'title' => 'This will be ignored if ID 1 exists' ]); $uniqueInserter->execute(); // Upsert - insert or update on conflict $upserter = $factory->createUpsert(Article::class, ['title', 'content']); $upserter->addRaw([ 'id' => 1, 'title' => 'Updated Title', 'content' => 'Updated content...' ]); $upserter->execute();
Update Operations
// Standard update for smaller datasets $updater = $factory->createUpdate(Article::class, ['id']); $updater->addRaw([ 'id' => 1, 'title' => 'Updated Title', 'updated_at' => new DateTime() ]); $updater->execute(); // Big update for large datasets - uses temporary tables $bigUpdater = $factory->createBigUpdate(Article::class, ['id']); // Add thousands of records... $bigUpdater->execute();
Direct Usage (Alternative)
You can also create operations directly:
use Shredio\RapidDatabaseOperations\Doctrine\DoctrineRapidInserter; use Shredio\RapidDatabaseOperations\Doctrine\DoctrineRapidUpdater; // Direct inserter creation $inserter = new DoctrineRapidInserter(Article::class, $entityManager); $inserter->addRaw(['id' => 1, 'title' => 'Title']); $inserter->execute(); // Direct updater creation $updater = new DoctrineRapidUpdater(Article::class, $entityManager); $updater->addRaw(['id' => 1, 'title' => 'Updated Title']); $updater->execute();
Operation Types
createInsert(string $entity)
Creates a basic insert operation that will fail if duplicate keys are encountered.
createUniqueInsert(string $entity)
Creates an insert operation that silently ignores duplicate records using INSERT ... ON DUPLICATE KEY ... DO NOTHING.
createUpsert(string $entity, array $fieldsToUpdate = [])
Creates an upsert operation that inserts new records or updates existing ones on conflict. You can specify which fields to update, or leave empty to update all fields.
createUpdate(string $entity, array $conditions)
Creates a standard update operation using direct UPDATE statements. Best for smaller datasets.
createBigUpdate(string $entity, array $conditions)
Creates an optimized update operation that uses temporary tables for better performance with large datasets.
Symfony Integration
The library includes a Symfony bundle for easy integration:
// config/bundles.php return [ // ... Shredio\RapidDatabaseOperations\Symfony\RapidDatabaseOperationsBundle::class => ['all' => true], ];
Development
Running Tests
composer test
Static Analysis
composer phpstan
shredio/rapid-database-operations 适用场景与选型建议
shredio/rapid-database-operations 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 487 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 05 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 shredio/rapid-database-operations 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 shredio/rapid-database-operations 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 487
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-15