【问题标题】:Can Doctrine DBAL do batch inserts?Doctrine DBAL 可以批量插入吗?
【发布时间】:2013-07-29 03:21:32
【问题描述】:

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

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

【问题讨论】:

    标签: php doctrine dbal


    【解决方案1】:

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

    Doctrine2 使用 UnitOfWork 模式,所以基本上你可以“持久化”多条记录,然后在最后运行flush - 它会找出插入/更新/等所有数据的最有效方法。这很聪明。

    【讨论】:

    • 关于 Doctrine DBAL 的原始问题,而不是 Doctrine 2 ORM。这不仅仅是不同的 Doctrine 版本,而是针对不同需求具有不同抽象级别的不同库。
    • 同意@MykolaZyk
    猜你喜欢
    • 2015-07-17
    • 2015-09-29
    • 2016-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-07
    • 1970-01-01
    相关资源
    最近更新 更多