mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 22:31:13 -05:00
Refactor code structure and remove redundant changes
This commit is contained in:
55
src-old/lib/supabaseHelpers.ts
Normal file
55
src-old/lib/supabaseHelpers.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Type-safe Supabase query helpers
|
||||
*
|
||||
* Provides type-safe table query builders to eliminate `as any` assertions.
|
||||
*/
|
||||
|
||||
import { supabase } from '@/lib/supabaseClient';
|
||||
import type { Database } from '@/integrations/supabase/types';
|
||||
|
||||
// Define valid table names from the database schema
|
||||
export type TableName = keyof Database['public']['Tables'];
|
||||
|
||||
/**
|
||||
* Create a type-safe query builder for a specific table
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* const query = createTableQuery('parks').select('*').eq('slug', 'disneyland');
|
||||
* const query2 = createTableQuery('rides').select('id, name').eq('status', 'operating');
|
||||
* ```
|
||||
*/
|
||||
export function createTableQuery<T extends TableName>(tableName: T) {
|
||||
return supabase.from(tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically query a table by name with type safety
|
||||
*
|
||||
* Use this when the table name is determined at runtime (e.g., version tables).
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* const versions = await queryTable('park_versions', (q) =>
|
||||
* q.select('*').eq('park_id', parkId)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export async function queryTable<T extends TableName>(
|
||||
tableName: T,
|
||||
queryBuilder: (query: ReturnType<typeof createTableQuery<T>>) => any
|
||||
) {
|
||||
const query = createTableQuery(tableName);
|
||||
return queryBuilder(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Type-safe interface for processed uploaded images
|
||||
*/
|
||||
export interface ProcessedImage {
|
||||
url: string;
|
||||
cloudflare_id: string;
|
||||
order: number;
|
||||
title?: string;
|
||||
caption?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user