# Book Catalog with Named Parameters # Demonstrates using named SQL parameters for better readability load_module target/debug/libsqlite_serve.dylib; worker_processes 1; events {} error_log logs/error.log debug; http { sqlite_global_templates "server_root/global_templates"; server { listen 8082; root "server_root"; # Book detail with named parameter location = /book { add_header "Content-Type" "text/html; charset=utf-8"; sqlite_db "book_catalog.db"; sqlite_query "SELECT * FROM books WHERE id = :book_id"; sqlite_param :book_id $arg_id; sqlite_template "detail.hbs"; } # Genre filter with named parameter location = /genre { add_header "Content-Type" "text/html; charset=utf-8"; sqlite_db "book_catalog.db"; sqlite_query "SELECT * FROM books WHERE genre = :genre_name ORDER BY rating DESC"; sqlite_param :genre_name $arg_genre; sqlite_template "genre.hbs"; } # Year range with named parameters location = /years { add_header "Content-Type" "text/html; charset=utf-8"; sqlite_db "book_catalog.db"; sqlite_query "SELECT * FROM books WHERE year >= :min_year AND year <= :max_year ORDER BY year DESC, title"; sqlite_param :min_year $arg_min; sqlite_param :max_year $arg_max; sqlite_template "list.hbs"; } # Search by title with named parameter location = /search { add_header "Content-Type" "text/html; charset=utf-8"; sqlite_db "book_catalog.db"; sqlite_query "SELECT * FROM books WHERE title LIKE '%' || :search_term || '%' ORDER BY rating DESC, title"; sqlite_param :search_term $arg_q; sqlite_template "list.hbs"; } # Filter by rating with named parameter location = /top-rated { add_header "Content-Type" "text/html; charset=utf-8"; sqlite_db "book_catalog.db"; sqlite_query "SELECT * FROM books WHERE rating >= :min_rating ORDER BY rating DESC, title"; sqlite_param :min_rating $arg_rating; sqlite_template "list.hbs"; } # Fallback to all books location / { add_header "Content-Type" "text/html; charset=utf-8"; sqlite_db "book_catalog.db"; sqlite_query "SELECT * FROM books ORDER BY rating DESC, title"; sqlite_template "list.hbs"; } } }