getCinemas()
Get all cinemas in the database, ordered alphabetically by name.
Returns
Array of all cinemas sorted by name
Unique identifier for the cinema
Short location name or code
Full descriptive location name (preferred for display)
Physical address of the cinema
ISO timestamp when the cinema was created
ISO timestamp when the cinema was last updated
Example
import { getCinemas } from '@/lib/queries';
const cinemas = await getCinemas();
// Returns all cinemas alphabetically by name
Implementation
const { data, error } = await supabase
.from('cinemas')
.select('*')
.order('name');
getCinemaById()
Get a single cinema by its ID.
Parameters
The unique identifier of the cinema to retrieve
Returns
Single cinema object with all properties
Example
import { getCinemaById } from '@/lib/queries';
const cinema = await getCinemaById(5);
console.log(cinema.name);
console.log(cinema.verbose_location || cinema.location);
Implementation
const { data, error } = await supabase
.from('cinemas')
.select('*')
.eq('id', id)
.single();
getAllCinemaIds()
Get all cinema IDs and names. Useful for static path generation in Astro.
Returns
cinemaIds
Promise<{ id: number; name: string }[]>
Array of objects containing cinema IDs and names
Example
import { getAllCinemaIds, generateSlug } from '@/lib/queries';
// In Astro getStaticPaths
export async function getStaticPaths() {
const cinemas = await getAllCinemaIds();
return cinemas.map((cinema) => ({
params: {
id: `${cinema.id}-${generateSlug(cinema.name)}`
}
}));
}
Implementation
const { data, error } = await supabase
.from('cinemas')
.select('id, name');
Helper Functions
getDisplayLocation()
Helper function to get the preferred display location for a cinema. Returns verbose_location if available, otherwise falls back to location.
Parameters
Returns
The display-friendly location string
Example
import { getCinemaById, getDisplayLocation } from '@/lib/queries';
const cinema = await getCinemaById(5);
const location = getDisplayLocation(cinema);
console.log(location); // Shows verbose_location or location
Implementation
export function getDisplayLocation(cinema: Cinema): string | null {
return cinema.verbose_location || cinema.location;
}