cube.js 执行环境

cube.js 使用node vm 进行schema 的编译,提供了灵活的编译schema 的能力

cube.js 提供的全局对象

cube(), context() asyncModule()

import && export 的处理

数据schema 定义的es6 文件,将会被编译为nodejs 的调用,import 变为Require
export 会被定义为exports ,当然核心依赖的还是babel

asyncModule

一个方便的动态schema 编译处理扩展

上下文符号编译

cube 对于部分保留的schema 定义进行了自己的编译处理(注意是在cube 函数内部定义的)
内部需要处理的

 
sql
measureReferences
dimensionReferences
segmentReferences
timeDimensionReference
drillMembers
drillMemberReferences
contextMembers 

以上的定义会被编译为函数,同时保留传递的参数,参考

cube(`Users`, {
  // ...
 
 
  measures: {
    count: {
      type: `count`,
    },
    ratio: {
      sql: `sum(${CUBE}.amount) / ${count}`,
      type: `number`,
    },
  },
});

编译为

cube(`Users`, {
  // ...
  measures: {
    count: {
      type: `count`,
    },
    ratio: {
      sql: (CUBE, count) => `sum(${CUBE}.amount) / ${count}`,
      type: `number`,
    },
  },
});

所以如果需要自己传递一些定义(cube 函数外部),就需要使用函数模式
参考

 
const measureRatioDefinition = {
  sql: (CUBE, count) => `sum(${CUBE}.amount) / ${count}`,
  type: `number`,
};
cube(`Users`, {
  // ...
  measures: {
    count: {
      type: `count`,
    },
    ratio: measureRatioDefinition,
  },
});

说明

说明
以上部分对于cube.js 内部的理解还是很有用的,以前官方文档并没有太多的介绍,目前来说文档还是比较全了

参考资料

https://cube.dev/docs/schema-execution-environment

posted on   荣锋亮  阅读(180)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2019-01-24 openresty 一些可选的模板引擎
2019-01-24 openresty router && template 试用
2017-01-24 nginx 启用http2 https 无法访问的问题

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示