cube.js schema 预编译处理

在实际开发中,对于schema 检查是很重要的,不然一个异常的schema 会造成整个系统服务的不可用

参考进行schema预编译的处理

  • 参考做法
    自己定义一个,同时使用schema 编译包提供的方法
 
import { prepareCompiler as originalPrepareCompiler } from '../../src/compiler/PrepareCompiler';
export const prepareCompiler = (content, options) => originalPrepareCompiler({
  localPath: () => __dirname,
  dataSchemaFiles: () => Promise.resolve([
    { fileName: 'main.js', content }
  ])
}, { adapter: 'postgres', ...options });
  • 参考使用
const { compiler } = prepareCompiler(`
    cube('visitors', {
      sql: \`
      select * from visitors
      \`,
 
      measures: {
        visitor_count: {
          type: 'count',
          sql: 'id',
          drillMembers: [source, created_at]
        },
        visitor_revenue: {
          type: 'sum',
          sql: 'amount',
          drillMemberReferences: [source, created_at]
        }
      },
 
      dimensions: {
        source: {
          type: 'string',
          sql: 'source'
        },
        created_at: {
          type: 'time',
          sql: 'created_at'
        }
      }
    })
    `);
return compiler.compile();

说明

以上代码来自官方文档还是比较有用的,可以提高系统的稳健性

参考资料

https://github.com/cube-js/cube.js/blob/master/packages/cubejs-schema-compiler/test/unit/PrepareCompiler.js

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

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2019-04-10 nomad 0.9 新特性
2019-04-10 goaccess geoip 测试
2018-04-10 elixir 几种安装方式
2018-04-10 一张elixir生产环境部署的图
2017-04-10 基于jquery 的ajax 文件下载
2014-04-10 无法对 数据库'XXXXX' 执行 删除,因为它正用于复制

导航

< 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
点击右上角即可分享
微信分享提示