getNowShowingMovies()
Get all movies that are currently showing (have at least one future showtime). Results are sorted by earliest showtime, then alphabetically by title.
Returns
Array of movies with future showtimes
Unique identifier for the movie
Movie description or synopsis
Year the movie was released
Movie duration in minutes
URL to the movie poster image
ISO timestamp when the movie was created
ISO timestamp when the movie was last updated
Example
import { getNowShowingMovies } from '@/lib/queries';
const movies = await getNowShowingMovies();
// Returns movies sorted by earliest showtime
Implementation
Uses Supabase inner join to filter movies with future showtimes:
const now = new Date().toISOString();
const { data, error } = await supabase
.from('movies')
.select(`
*,
showtimes!inner(id, start_time)
`)
.gte('showtimes.start_time', now);
getMovieById()
Get a single movie by its ID.
Parameters
The unique identifier of the movie to retrieve
Returns
Single movie object with all properties
Example
import { getMovieById } from '@/lib/queries';
const movie = await getMovieById(123);
console.log(movie.title);
Implementation
const { data, error } = await supabase
.from('movies')
.select('*')
.eq('id', id)
.single();
getAllMovies()
Get all movies in the database, ordered alphabetically by title.
Returns
Array of all movies sorted by title
Example
import { getAllMovies } from '@/lib/queries';
const movies = await getAllMovies();
// Returns all movies alphabetically
Implementation
const { data, error } = await supabase
.from('movies')
.select('*')
.order('title');
getAllMovieIds()
Get all movie IDs and titles. Useful for static path generation in Astro.
Returns
movieIds
Promise<{ id: number; title: string }[]>
Array of objects containing movie IDs and titles
Example
import { getAllMovieIds, generateSlug } from '@/lib/queries';
// In Astro getStaticPaths
export async function getStaticPaths() {
const movies = await getAllMovieIds();
return movies.map((movie) => ({
params: {
id: `${movie.id}-${generateSlug(movie.title)}`
}
}));
}
Implementation
const { data, error } = await supabase
.from('movies')
.select('id, title');