【问题标题】:Does realm Javascript supports Join, Group By and Aggregation functions领域 Javascript 是否支持 Join、Group By 和 Aggregation 函数
【发布时间】:2017-05-03 02:44:23
【问题描述】:

要开发一个显示统计数据的 React Native 移动应用程序,以下功能将被广泛使用,Realm 是否可以满足需求?

加入
分组
聚合
自动增量

请推荐任何其他最适合统计应用的 ORM/DB?

【问题讨论】:

  • Realm 不是关系数据库,所以虽然有聚合,但没有连接(有链接)之类的东西,也没有 groupBy 之类的东西(因为你检索整个对象,或者更具体地说是一种观点)。自动增量在技术上是“max+1”,所以它不是不可能的。

标签: react-native realm realm-mobile-platform


【解决方案1】:

替代方案

您可以在Realm Database 中获取日期,然后使用js group by

// Accepts the array and key
const groupBy = (array, key) => {
  // Return the end result
  return array.reduce((result, currentValue) => {
    // If an array already present for key, push it to the array. Else create an array and push the object
    (result[currentValue[key]] = result[currentValue[key]] || []).push(
      currentValue
    );
    // Return the current iteration `result` value, this will be taken as next iteration `result` value and accumulate
    return result;
  }, {}); // empty object is the initial value for result object
};

// Group by color as key to the person array
const personGroupedByColor = groupBy(person, 'color');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-07
    • 1970-01-01
    • 2016-03-06
    • 2014-11-19
    • 2014-08-31
    • 1970-01-01
    • 2016-04-11
    相关资源
    最近更新 更多