在 Ionic 4 中返回行 COUNT

Posted

技术标签:

【中文标题】在 Ionic 4 中返回行 COUNT【英文标题】:Return rows COUNT in Ionic 4 【发布时间】:2019-08-18 17:16:59 【问题描述】:

我正在使用 Ionic 应用程序。我有 SQLITE 数据库。在数据库中,我有一个名为“words”的表。现在我想得到这张表中有多少行。我正在使用我认为正确的 COUNT(*) SQL 命令,因为它非常简单,但是在将数字获取到我的 words.page.ts 文件时遇到问题,函数 getWordsCount() 不起作用,它返回 [object承诺]。

getWordsCount()
  let count;
  count = this.database.executeSql("select count(*) from words", []);
  return count;

实际结果:[object Promise]

预期结果:任意数字(此时为 4)

【问题讨论】:

使用asyncawait方法 【参考方案1】:

database.executeSql 方法是一个 Promise。你必须等到 promise 得到解决才能得到结果。

async getWordsCount()
  let count;
  count = await this.database.executeSql("select count(*) from words", []);
  return count;

【讨论】:

以上是关于在 Ionic 4 中返回行 COUNT的主要内容,如果未能解决你的问题,请参考以下文章