2013-07-29 84 views
4

是否可以对SQLite DB使用Doctrine DBAL进行批量插入?即使以下更高效: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)); 
     } 
    } 

回答

-2

随着Doctrine2,是的! http://doctrine-orm.readthedocs.org/en/latest/reference/batch-processing.html

Doctrine2使用的UnitOfWork模式,所以基本上可以“坚持”的多条记录,然后用鼠标右键在运行结束flush - 它会找出最有效的方法插入/更新/ etc中的所有数据。这很聪明。

+3

原始问题关于教条** DBAL **,而不是教条2 ** ORM **。这不仅仅是不同的Doctrine版本,它是针对不同需求具有不同抽象级别的不同库。 –

+0

同意@MykolaZyk – Sergey