@@ -242,6 +242,38 @@ const ordersJs = `cube(\`orders\`, {
242242});
243243` ;
244244
245+ const exampleViewJs = `// In Cube, views are used to expose slices of your data graph and act as data marts.
246+ // You can control which measures and dimensions are exposed to BIs or data apps,
247+ // as well as the direction of joins between the exposed cubes.
248+ // You can learn more about views in documentation here - https://cube.dev/docs/schema/reference/view
249+
250+ // The following example shows a view defined on top of orders and customers cubes.
251+ // Both orders and customers cubes are exposed using the "includes" parameter to
252+ // control which measures and dimensions are exposed.
253+ // Prefixes can also be applied when exposing measures or dimensions.
254+ // In this case, the customers' city dimension is prefixed with the cube name,
255+ // resulting in "customers_city" when querying the view.
256+
257+ // view(\`example_view\`, {
258+ // cubes: [
259+ // {
260+ // join_path: orders,
261+ // includes: [
262+ // 'status',
263+ // 'created_date',
264+ // ],
265+ // },
266+ // {
267+ // join_path: orders.customers,
268+ // prefix: true,
269+ // includes: [
270+ // 'city',
271+ // ],
272+ // },
273+ // ]
274+ // });
275+ ` ;
276+
245277const ordersYml = `cubes:
246278 - name: orders
247279 sql: >
@@ -273,6 +305,36 @@ const ordersYml = `cubes:
273305 type: string
274306` ;
275307
308+ const exampleViewYml = `# In Cube, views are used to expose slices of your data graph and act as data marts.
309+ # You can control which measures and dimensions are exposed to BIs or data apps,
310+ # as well as the direction of joins between the exposed cubes.
311+ # You can learn more about views in documentation here - https://cube.dev/docs/schema/reference/view
312+
313+ # The following example shows a view defined on top of orders and customers cubes.
314+ # Both orders and customers cubes are exposed using the "includes" parameter to
315+ # control which measures and dimensions are exposed.
316+ # Prefixes can also be applied when exposing measures or dimensions.
317+ # In this case, the customers' city dimension is prefixed with the cube name,
318+ # resulting in "customers_city" when querying the view.
319+
320+ # views:
321+ # - name: example_view
322+ #
323+ # cubes:
324+ # - join_path: orders
325+ # includes:
326+ # - status
327+ # - created_date
328+ #
329+ # - total_amount
330+ # - count
331+ #
332+ # - join_path: orders.customers
333+ # prefix: true
334+ # includes:
335+ # - city
336+ ` ;
337+
276338const cubeJs = `// Cube configuration options: https://cube.dev/docs/config
277339/** @type{ import('@cubejs-backend/server-core').CreateOptions } */
278340module.exports = {
@@ -307,7 +369,8 @@ const templates: Record<string, Template> = {
307369 'docker-compose.yml' : dockerCompose ,
308370 '.env' : dotEnv ,
309371 '.gitignore' : ( ) => gitIgnore ,
310- 'model/cubes/orders.js' : ( ) => ordersJs
372+ 'model/cubes/orders.js' : ( ) => ordersJs ,
373+ 'model/views/example_view.js' : ( ) => exampleViewJs ,
311374 }
312375 } ,
313376 docker : {
@@ -319,7 +382,8 @@ const templates: Record<string, Template> = {
319382 'docker-compose.yml' : dockerCompose ,
320383 '.env' : dotEnv ,
321384 '.gitignore' : ( ) => gitIgnore ,
322- 'model/cubes/orders.yml' : ( ) => ordersYml
385+ 'model/cubes/orders.yml' : ( ) => ordersYml ,
386+ 'model/views/example_view.yml' : ( ) => exampleViewYml ,
323387 }
324388 } ,
325389 express : {
0 commit comments