{
  "smaltui": 1,
  "name": "Demo shop",
  "description": "A small tea & coffee shop: products, customers, orders, a view, a materialized view, a linked CSV of exchange rates and sales data imported from a Parquet file. Sample data only.",
  "database": {
    "name": "demo",
    "storage": "memory"
  },
  "init": "always",
  "steps": [
    {
      "sqlFile": "schema.sql"
    },
    {
      "import": "data/products.csv",
      "table": "products"
    },
    {
      "import": "data/customers.json",
      "table": "customers"
    },
    {
      "import": "data/orders.csv",
      "table": "orders"
    },
    {
      "link": "data/exchange_rates.csv",
      "table": "exchange_rates",
      "format": "csv"
    },
    {
      "import": "data/regional_sales.parquet",
      "table": "regional_sales",
      "format": "parquet"
    },
    {
      "sqlFile": "views.sql"
    }
  ],
  "queries": [
    {
      "title": "Revenue by category",
      "sql": "-- Ctrl+Enter runs the statement under the cursor\nSELECT category,\n       count(*) AS lines,\n       sum(quantity) AS units,\n       round(sum(amount), 2) AS revenue\nFROM order_lines\nWHERE status <> 'cancelled'\nGROUP BY category\nORDER BY revenue DESC;\n\n-- Top customers, revenue converted to USD through the linked exchange_rates CSV\nSELECT c.name, c.country, c.currency,\n       round(sum(o.quantity * p.price), 2) AS revenue,\n       round(sum(o.quantity * p.price) * r.usd_per_unit, 2) AS revenue_usd\nFROM orders o\nJOIN customers c ON c.id = o.customer_id\nJOIN products p ON p.id = o.product_id\nJOIN exchange_rates r ON r.currency = c.currency\nGROUP BY c.id, c.name, c.country, c.currency, r.usd_per_unit\nORDER BY revenue_usd DESC\nLIMIT 10;\n"
    },
    {
      "title": "Window functions",
      "sql": "-- Running revenue per month (from the materialized view)\nSELECT month, orders, revenue,\n       sum(revenue) OVER (ORDER BY month) AS running_total,\n       rank() OVER (ORDER BY revenue DESC) AS rank_by_revenue\nFROM monthly_revenue\nORDER BY month;\n\n-- Bind variables: you will be asked for :country\nSELECT name, signed_up FROM customers WHERE country = :country ORDER BY signed_up;\n\nEXPLAIN QUERY PLAN\nSELECT * FROM orders WHERE customer_id = 7 ORDER BY ordered_at;\n"
    },
    {
      "title": "Parquet",
      "sql": "-- regional_sales was imported from a Parquet file (data/regional_sales.parquet).\n-- The Import tab and environment \"import\" steps read Parquet like CSV or JSON.\nSELECT region,\n       count(*) AS sales,\n       sum(amount) AS total,\n       min(day) AS first_day,\n       max(day) AS last_day\nFROM regional_sales\nGROUP BY region\nORDER BY total DESC;\n\n-- Monthly totals per region\nSELECT substr(day, 1, 7) AS month, region, sum(amount) AS total\nFROM regional_sales\nGROUP BY 1, 2\nORDER BY 1, 3 DESC\nLIMIT 24;\n"
    }
  ],
  "open": [
    "orders"
  ]
}
