Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlite addMany 方法返回值有问题 #388

Closed
rindybo opened this issue Jul 8, 2016 · 0 comments
Closed

sqlite addMany 方法返回值有问题 #388

rindybo opened this issue Jul 8, 2016 · 0 comments

Comments

@rindybo
Copy link

rindybo commented Jul 8, 2016

DESC

  async addMany(data, options, replace){
    if (!think.isArray(data) || !think.isObject(data[0])) {
      return think.reject(new Error(think.locale('DATA_MUST_BE_ARRAY')));
    }
    if (options === true) {
      replace = true;
      options = {};
    }
    options = await this.parseOptions(options);
    let promises = data.map(item => {
      item = this.parseData(item);
      return this.beforeAdd(item, options);
    });
    data = await Promise.all(promises);
    await this.db().addMany(data, options, replace);
    let insertId = this.db().getLastInsertId();
    let insertIds = [];
    promises = data.map((item, i) => {
      let id = insertId + i;
      item[this.pk] = id;
      insertIds.push(id);
      return this.afterAdd(item, options);
    });
    data = await Promise.all(promises);
    return insertIds;
  }

this.db().getLastInsertId();获取的是添加数据后的最后一行的id,
下面循环递增的代码就不正确了

ENV

2.2.x
Platform:
window10
Node.js Version:
4.2.x
ThinkJS Version:

@welefen welefen closed this as completed in cd414b2 Aug 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant