Pregunta

Is it possible to do batch inserts using Doctrine DBAL against a SQLite DB? i.e make the following more efficient:

$twitter = new TwitterAPIExchange($twitterAuth);
    $response = json_decode($twitter->setGetfield($getField)
        ->buildOauth($url, $requestMethod)
        ->performRequest());

    foreach($response->statuses as $r) {
        $statement = $app['db']->executeQuery('SELECT * FROM tweets WHERE twitter_id = ?', array($r->id));
        $tweet = $statement->fetch();

        if(empty($tweet)) {
            $app['db']->insert('tweets', array('twitter_id'=>$r->id, 'contents' => $r->text, 'timestamp' => $r->created_at));
        }
    }
¿Fue útil?

Solución

With Doctrine2, yes! http://doctrine-orm.readthedocs.org/en/latest/reference/batch-processing.html

Doctrine2 uses the UnitOfWork pattern, so basically you can "persist" multiple records, and then right at the end run flush - and it will figure out the most efficient method to insert/update/etc all the data. It's pretty clever.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top