oscklmO
Convex Community3y ago
3 replies
oscklm

Any thoughts/feedback on this approach?

Any thoughts/feedback on this approach? I'm using categories in a select input in my create videos form. Curious as to how i could improve it, or if i'm completely missing out on some smarter way to do this 🤔

// schema.ts
export const CATEGORIES = [
  'Kreativitet',
  'Computer',
  'Gaming',
  'Musik',
  'Sport',
  'Viden',
  'Hverdag',
  'Nørderi',
  'Natur',
] as const;

const CategoryLiterals = CATEGORIES.map((c) => v.literal(c));

export const videos = {
  title: v.string(),
  description: v.optional(v.string()),
  tags: v.array(v.string()),
  category: v.union(
    CategoryLiterals[0],
    CategoryLiterals[1],
    ...CategoryLiterals
  ),
  visibility: v.union(v.literal('public'), v.literal('private')),
  muxPlaybackId: v.optional(v.string()),
  muxAssetId: v.optional(v.string()),
};

export default defineSchema({
  videos: defineTable(videos),
});
Was this page helpful?