[英]How to pass dynamic values in sql in cube.js schema?
Somewhere I want status=2 or status<3.我想要状态= 2或状态<3的地方。 Instead of writing separate schemas, how to reuse by passing dynamic values to the status field in SQL?如何通过将动态值传递给 SQL 中的状态字段来重用,而不是编写单独的模式?
cube(`OrderFacts`, {
sql: `SELECT * FROM orders WHERE status>3`, // <--- I want to pass dynamic values to the condition
measures: {
count: {
type: `count`
}
},
dimensions: {
date: {
sql: `date`,
type: `time`
}
}
});
Please refer to the Unsafe Value section of the Context Variables documentation:请参阅上下文变量文档的不安全值部分:
cube(`Orders`, {
sql: `SELECT * FROM orders WHERE status > ${SECURITY_CONTEXT.status.unsafeValue()`,
});
Generally speaking, it's best not to do this though;一般来说,最好不要这样做; instead I'd recommend using segments to achieve the same functionality (assuming there aren't a lot of values for status
)相反,我建议使用段来实现相同的功能(假设status
没有很多值)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.