Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,15 @@ which can be found in the `src/data` directory.

## Demo

See the [demo](https://marimo-team.github.io/codemirror-sql/) for a full example.
Run the interactive vNext playground locally:

```bash
pnpm dev
```

The playground exercises relation, namespace, physical-column, CTE, correlated
scope, and `LATERAL` completion against an in-memory catalog. It also exposes
provider latency and catalog invalidation controls.

## Development

Expand Down
157 changes: 70 additions & 87 deletions demo/data.ts
Original file line number Diff line number Diff line change
@@ -1,92 +1,75 @@
import type { Schema } from "./custom-renderers.js";
export interface DemoTable {
readonly columns: readonly {
readonly name: string;
readonly type: string;
}[];
readonly description: string;
readonly name: string;
readonly schema: string;
}

// Default SQL content for the demo
export const defaultSqlDoc = `-- Welcome to the SQL Editor Demo!
-- Try editing the queries below to see real-time validation
export const demoTables: readonly DemoTable[] = [
{
columns: [
{ name: "id", type: "BIGINT" },
{ name: "name", type: "VARCHAR" },
{ name: "email", type: "VARCHAR" },
{ name: "active", type: "BOOLEAN" },
{ name: "created_at", type: "TIMESTAMP" },
],
description: "Application users",
name: "users",
schema: "main",
},
{
columns: [
{ name: "id", type: "BIGINT" },
{ name: "user_id", type: "BIGINT" },
{ name: "title", type: "VARCHAR" },
{ name: "published", type: "BOOLEAN" },
{ name: "created_at", type: "TIMESTAMP" },
],
description: "Published and draft posts",
name: "posts",
schema: "main",
},
{
columns: [
{ name: "id", type: "BIGINT" },
{ name: "customer_id", type: "BIGINT" },
{ name: "order_date", type: "DATE" },
{ name: "total_amount", type: "DECIMAL(18, 2)" },
{ name: "status", type: "VARCHAR" },
],
description: "Customer orders",
name: "orders",
schema: "sales",
},
{
columns: [
{ name: "id", type: "BIGINT" },
{ name: "first_name", type: "VARCHAR" },
{ name: "last_name", type: "VARCHAR" },
{ name: "email", type: "VARCHAR" },
{ name: "country", type: "VARCHAR" },
],
description: "Customer directory",
name: "customers",
schema: "sales",
},
] as const;

-- Put the cursor on a CTE name or alias to highlight its references;
-- Cmd/Ctrl-click (or F12) jumps to the definition, F2 renames.
WITH recent_orders AS (
SELECT customer_id, total_amount FROM orders WHERE order_date >= '2024-01-01'
),
top_customers AS (
SELECT customer_id, SUM(total_amount) AS total_spent
FROM recent_orders
GROUP BY customer_id
)
SELECT c.first_name, t.total_spent AS amount
FROM customers c
JOIN top_customers t ON t.customer_id = c.id
ORDER BY amount DESC;
export const defaultSqlDoc = `-- vNext SQL language-service playground
-- Press Ctrl-Space anywhere completion is expected.

-- Valid queries (no errors):
SELECT id, name, email
FROM users
WHERE active = true
ORDER BY created_at DESC;
SELECT u.
FROM main.users AS u
WHERE EXISTS (
SELECT 1
FROM sales.orders AS o
WHERE o.customer_id = u.id
);

SELECT
u.name,
p.title,
p.created_at
FROM users u
JOIN posts p ON u.id = p.user_id
WHERE u.status = 'active'
AND p.published = true
LIMIT 10;

-- Try editing these to create syntax errors:
-- Uncomment the lines below to see error highlighting

-- SELECT * FROM; -- Missing table name
-- SELECT * FORM users; -- Typo in FROM keyword
-- INSERT INTO VALUES (1, 2); -- Missing table name
-- UPDATE SET name = 'test'; -- Missing table name

-- Complex example with subquery:
SELECT
customer_id,
order_date,
total_amount,
(SELECT AVG(total_amount) FROM orders) as avg_order_value
FROM orders
WHERE order_date >= '2024-01-01'
AND total_amount > (
SELECT AVG(total_amount) * 0.8
FROM orders
WHERE YEAR(order_date) = 2024
)
ORDER BY total_amount DESC;
SELECT *
FROM sales.
`;

export const schema: Record<Schema, string[]> = {
// Users table
users: ["id", "name", "email", "active", "status", "created_at", "updated_at", "profile_id"],
// Posts table
posts: [
"id",
"title",
"content",
"user_id",
"published",
"created_at",
"updated_at",
"category_id",
],
// Orders table
orders: [
"id",
"customer_id",
"order_date",
"total_amount",
"status",
"shipping_address",
"created_at",
],
// Customers table (additional example)
customers: ["id", "first_name", "last_name", "email", "phone", "address", "city", "country"],
// Categories table
categories: ["id", "name", "description", "parent_id"],
// Users_Posts table
Users_Posts: ["user_id", "post_id"],
};
Loading
Loading