1. MooseStack
  2. Moose OLAP
  3. Modeling Views

On this page

OverviewBasic UsageQuick Reference

Modeling Views

Overview

Views are read-time projections in ClickHouse. A static SELECT defines the view over one or more base tables or other views. Moose wraps ClickHouse VIEW with a simple View class in TypeScript or Python. You provide the view name, the SELECT, and the list of source tables/views so Moose can order DDL correctly during migrations.

When to use a View

Use View when you want a virtual read-time projection and don't need write-time transformation or a separate storage table. For write-time pipelines and backfills, use a Materialized View instead.

Basic Usage

import { View, sql } from "@514labs/moose-lib";import { users } from "./Users";import { events } from "./Events"; export const activeUserEvents = new View(  "active_user_events",  sql`    SELECT      ${events.columns.id}    AS event_id,      ${users.columns.id}     AS user_id,      ${users.columns.name}   AS user_name,      ${events.columns.ts}    AS ts    FROM ${events}    JOIN ${users} ON ${events.columns.user_id} = ${users.columns.id}    WHERE ${users.columns.active} = 1  `,  [events, users],);

Quick Reference

// new View(name, selectStatement, baseTables)new View(  "view_name",  sql`SELECT ... FROM ${someTable}`,  [someTable, /* other tables or views */],);
Static SQL recommended

The SELECT should be static (no runtime parameters). In TypeScript, prefer Moose's sql template for safe table/column interpolation; in Python, use string templates with {table.columns.col}.

  • Overview
  • Quick Start
  • Templates / Examples
Fundamentals
  • Moose Runtime
  • MooseDev MCP
  • Data Modeling
MooseStack in your App
  • App / API frameworks
Modules
  • Moose OLAP
    • Data Modeling
    • Tables
    • Views
    • Materialized Views
    • Materialized Columns
    • External Data & Introspection
    • External Tables
    • Introspecting Tables
    • Data Access
    • Inserting Data
    • Reading Data
    • Performance & Optimization
    • Schema Optimization
    • Secondary & Data-skipping Indexes
    • TTL (Time-to-Live)
    • Schema Versioning
  • Moose Streaming
  • Moose Workflows
  • Moose APIs
Deployment & Lifecycle
  • Moose Migrate
  • Moose Deploy
Reference
  • API Reference
  • Data Types
  • Table Engines
  • CLI
  • Configuration
  • Observability Metrics
  • Help
  • Changelog
Contribution
  • Documentation
  • Framework
FiveonefourFiveonefour
Fiveonefour Docs
MooseStackTemplates
Changelog
Source506