Doctrtrine DBAL可以批量插入吗?

时间:2013-07-29 11:00:02

标签: php doctrine dbal

是否可以针对SQLite数据库使用Doctrine DBAL进行批量插入?即使以下更有效:

$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));
        }
    }

1 个答案:

答案 0 :(得分:-3)

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

Doctrine2使用UnitOfWork模式,所以基本上你可以"坚持"多个记录,然后在最后运行flush - 它将找出插入/更新/等所有数据的最有效方法。它非常聪明。