NextUp Comedy Database Models

1.6.7 · active · verified Wed Apr 22

The `nc-db-new` package provides the foundational database models for the NextUp Comedy website and its associated services. Designed as an internal library, it centralizes the schema definitions, relationships, and often the data access logic for core entities such as Users, Shows, Venues, and Bookings specific to the comedy platform. Currently at version 1.6.7, this package ensures consistent data structures across various backend applications and microservices within the NextUp Comedy ecosystem. Its primary function is to abstract database interactions, enabling developers to work with TypeScript classes or interfaces that map directly to database tables. While its release cadence is tied to internal development cycles, it aims for stability in its minor and patch versions, with breaking changes typically confined to major version bumps. Key differentiators are its highly specialized domain model and its deep integration into the NextUp Comedy tech stack, providing a single source of truth for database schema.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates importing `User` and `Show` models, simulating database operations like creating and finding entities.

import { User, Show, db } from 'nc-db-new';

async function main() {
  // Assume 'db' is an initialized ORM instance or connection pool
  // For demonstration, we'll mock 'db.sync' and 'User.create'
  console.log('Synchronizing database models...');
  // await db.sync(); // In a real app, this might create/update tables
  console.log('Database models synchronized.');

  try {
    const newUser = await User.create({
      username: 'comedyfan',
      email: `fan_${Date.now()}@example.com`,
      passwordHash: 'hashedpassword123',
      is_admin: false
    });
    console.log('Created new user:', newUser.toJSON());

    const allUsers = await User.findAll();
    console.log('Total users:', allUsers.length);

    const firstShow = await Show.findOne({
      where: { title: 'The Laughter Gala' }
    });

    if (firstShow) {
      console.log('Found show:', firstShow.toJSON());
    } else {
      console.log('No show found with title "The Laughter Gala", creating one...');
      const createdShow = await Show.create({
        title: 'The Laughter Gala',
        date: new Date('2026-07-20T19:00:00Z'),
        venueId: 'venue-abc-123' // Assume a venue ID exists or is created elsewhere
      });
      console.log('Created new show:', createdShow.toJSON());
    }
  } catch (error) {
    console.error('Database operation failed:', error);
  }
}

// Simulate an initialized 'db' object and model methods for the quickstart
const mockDb = {
  sync: async () => Promise.resolve(),
};
const mockUser = {
  create: async (data: any) => ({ ...data, id: Math.random().toString(36).substring(7), toJSON: () => ({ ...data, id: 'mock-user-id' }) }),
  findAll: async () => ([{ username: 'existing', email: 'existing@example.com', toJSON: () => ({ username: 'existing', email: 'existing@example.com' }) }]),
  toJSON: () => ({}) // For compatibility
};
const mockShow = {
  findOne: async (options: any) => options.where.title === 'The Laughter Gala' ? null : ({ title: 'Existing Comedy Night', date: new Date(), toJSON: () => ({ title: 'Existing Comedy Night' }) }),
  create: async (data: any) => ({ ...data, id: Math.random().toString(36).substring(7), toJSON: () => ({ ...data, id: 'mock-show-id' }) })
};

// Overwrite for quickstart execution
// @ts-ignore
(globalThis as any).db = mockDb;
// @ts-ignore
(globalThis as any).User = mockUser;
// @ts-ignore
(globalThis as any).Show = mockShow;

main();

view raw JSON →