untitled-3483
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data โ all from the browser, and deployed in milliseconds.
This directory contains the database setup, migrations, and queries for the Toy Store website.
migrations.ts- Database schema setup and seed dataqueries.ts- Functions for querying the database
CREATE TABLE IF NOT EXISTS toy_store_categories (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
slug TEXT NOT NULL UNIQUE,
description TEXT
)
CREATE TABLE IF NOT EXISTS toy_store_products (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
slug TEXT NOT NULL UNIQUE,
description TEXT,
price REAL NOT NULL,
image_url TEXT,
category_id INTEGER,
featured BOOLEAN DEFAULT 0,
stock INTEGER DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (category_id) REFERENCES toy_store_categories(id)
)
getCategories()- Get all product categoriesgetCategoryBySlug(slug)- Get a category by sluggetProducts(options)- Get products with optional filteringgetProductBySlug(slug)- Get a product by sluggetFeaturedProducts(limit)- Get featured productssearchProducts(query)- Search products by name or description