tourze/doctrine-direct-insert-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tourze/doctrine-direct-insert-bundle

Composer 安装命令:

composer require tourze/doctrine-direct-insert-bundle

包简介

Symfony Bundle for direct database insertion of objects

README 文档

README

PHP Version License Build Status Code Coverage

English | 中文

A Symfony bundle that provides direct database insertion capabilities for Doctrine entities without using the ORM's persist/flush mechanism.

This bundle is designed for high-performance scenarios where you need to insert data directly into the database.

Features

  • Direct database insertion without ORM overhead
  • Support for auto-generated and preset IDs
  • Dedicated database connection support
  • Compatible with various data types (string, text, integer, float, boolean, nullable fields)
  • Automatic SQL generation based on entity metadata

Installation

composer require tourze/doctrine-direct-insert-bundle

Configuration

Add the bundle to your config/bundles.php:

<?php

return [
    // ... other bundles
    Tourze\DoctrineDirectInsertBundle\DoctrineDirectInsertBundle::class => ['all' => true],
];

Quick Start

Basic Usage

<?php

use Tourze\DoctrineDirectInsertBundle\Service\DirectInsertService;

class MyController
{
    public function __construct(
        private readonly DirectInsertService $directInsertService
    ) {
    }

    public function createEntity(): Response
    {
        $entity = new MyEntity();
        $entity->setName('Example Name');
        $entity->setEmail('example@example.com');
        
        // Insert directly into database and get the ID
        $id = $this->directInsertService->directInsert($entity);
        
        return new JsonResponse(['id' => $id]);
    }
}

With Preset ID

<?php

$entity = new MyEntity();
$entity->setId(12345); // Set a specific ID
$entity->setName('Example with preset ID');

$returnedId = $this->directInsertService->directInsert($entity);
// $returnedId will be 12345

Entity Example

<?php

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'my_entity')]
class MyEntity
{
    #[ORM\Id]
    #[ORM\Column(type: Types::INTEGER)]
    #[ORM\GeneratedValue(strategy: 'IDENTITY')]
    private ?int $id = null;

    #[ORM\Column(type: Types::STRING, length: 255)]
    private string $name;

    #[ORM\Column(type: Types::STRING, length: 255)]
    private string $email;

    // ... getters and setters
}

Advanced Usage

Dedicated Connection

This bundle supports dedicated database connections using the @WithDedicatedConnection attribute. The service uses a dedicated connection channel called direct_insert for improved performance and isolation.

Data Type Support

The bundle supports all standard Doctrine data types:

  • String and Text types
  • Integer and Float types
  • Boolean types
  • Nullable fields
  • Auto-generated IDs
  • Preset IDs

Performance Benefits

  • No ORM Overhead: Bypasses Doctrine's Unit of Work for faster insertions
  • Dedicated Connection: Uses a separate database connection to avoid conflicts
  • Direct SQL: Generates optimized INSERT statements directly
  • Batch Operations: Suitable for high-volume data insertion scenarios

Requirements

  • PHP 8.1+
  • Symfony 6.4+
  • Doctrine ORM 3.0+
  • Doctrine DBAL 4.0+

Dependencies

This bundle depends on:

  • tourze/doctrine-entity-checker-bundle - For SQL formatting utilities

License

This bundle is licensed under the MIT License. See the LICENSE file for details.

tourze/doctrine-direct-insert-bundle 适用场景与选型建议

tourze/doctrine-direct-insert-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.07k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 tourze/doctrine-direct-insert-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 tourze/doctrine-direct-insert-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 tourze/doctrine-direct-insert-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 10.07k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 10
  • 依赖项目数: 6
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-11