Skip to main content

Example Types

Below are generic entity types that can be used as a base for your database models. These follow a consistent pattern that can be extended for specific use cases.

// Base entity type with common fields
export type Entity = {
id?: string; // Primary key (usually UUID)
created_at?: string; // Creation timestamp
updated_at?: string; // Last update timestamp
};

// Example of extending the base entity
export type NamedEntity = Entity & {
name?: string; // Common name field
description?: string; // Optional description
};

// Example of a more specific entity
export type ContentEntity = NamedEntity & {
content?: string; // Content field
published?: boolean; // Publication status
author_id?: string; // Reference to another entity
metadata?: Record<string, any>; // Flexible metadata storage
};

// Example with nullable fields and specific types
export type MediaEntity = NamedEntity & {
url?: string; // Media URL
type?: 'image' | 'video' | 'audio' | 'document'; // Media type
size?: number; // File size in bytes
alt_text?: string | null; // Alternative text, can be null
external_id?: string | null; // External reference, can be null
};

These generic entity types provide a foundation that can be customized for specific business needs. The optional (?) properties can be undefined, and nullable fields are explicitly marked with the | null type.

When implementing specific entities for your application, you can extend these base types:

// Example of a specific implementation
export type User = NamedEntity & {
email: string; // Required field (no ? mark)
role: 'admin' | 'editor' | 'viewer';
profile_image?: string | null;
last_login?: string;
};