PHP code example of shredio / rapid-database-operations

1. Go to this page and download the library: Download shredio/rapid-database-operations library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shredio / rapid-database-operations example snippets


use Shredio\RapidDatabaseOperations\Doctrine\DoctrineRapidOperationFactory;

$factory = new DoctrineRapidOperationFactory($entityManager);

// 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();

// 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();

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();

// config/bundles.php
return [
    // ...
    Shredio\RapidDatabaseOperations\Symfony\RapidDatabaseOperationsBundle::class => ['all' => true],
];