forked from lunanting/cangku
80 lines
1.2 KiB
JavaScript
80 lines
1.2 KiB
JavaScript
// Cube.js 数据模型 - 产品示例
|
|
|
|
cube(`Products`, {
|
|
sql: `SELECT * FROM products WHERE \${this.enabled}`,
|
|
|
|
measures: {
|
|
count: {
|
|
sql: `id`,
|
|
type: `count`,
|
|
},
|
|
|
|
totalStock: {
|
|
sql: `stock`,
|
|
type: `sum`,
|
|
},
|
|
|
|
avgPrice: {
|
|
sql: `price`,
|
|
type: `avg`,
|
|
format: `currency`,
|
|
},
|
|
|
|
totalSales: {
|
|
sql: `sales_count`,
|
|
type: `sum`,
|
|
},
|
|
},
|
|
|
|
dimensions: {
|
|
id: {
|
|
sql: `id`,
|
|
type: `number`,
|
|
primaryKey: true,
|
|
},
|
|
|
|
name: {
|
|
sql: `name`,
|
|
type: `string`,
|
|
},
|
|
|
|
category: {
|
|
sql: `category`,
|
|
type: `string`,
|
|
},
|
|
|
|
price: {
|
|
sql: `price`,
|
|
type: `number`,
|
|
format: `currency`,
|
|
},
|
|
|
|
stock: {
|
|
sql: `stock`,
|
|
type: `number`,
|
|
},
|
|
|
|
status: {
|
|
sql: `status`,
|
|
type: `string`,
|
|
},
|
|
|
|
createdAt: {
|
|
sql: `created_at`,
|
|
type: `time`,
|
|
},
|
|
},
|
|
|
|
preAggregations: {
|
|
productsByCategory: {
|
|
measures: [Products.count, Products.totalStock, Products.totalSales],
|
|
dimensions: [Products.category],
|
|
timeDimension: Products.createdAt,
|
|
granularity: `day`,
|
|
refreshKey: {
|
|
every: `1 hour`,
|
|
},
|
|
},
|
|
},
|
|
});
|