Toy Store Database

This directory contains the database setup, migrations, and queries for the Toy Store website.

Files

  • migrations.ts - Database schema setup and seed data
  • queries.ts - Functions for querying the database

Database Schema

Categories Table

CREATE TABLE IF NOT EXISTS toy_store_categories ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, slug TEXT NOT NULL UNIQUE, description TEXT )

Products Table

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) )

Query Functions

  • getCategories() - Get all product categories
  • getCategoryBySlug(slug) - Get a category by slug
  • getProducts(options) - Get products with optional filtering
  • getProductBySlug(slug) - Get a product by slug
  • getFeaturedProducts(limit) - Get featured products
  • searchProducts(query) - Search products by name or description