Sequelize UI

  • sakila
    • models
import type { Sequelize, Model } from 'sequelize'
import { Actor } from './Actor'
import type { ActorAttributes, ActorCreationAttributes } from './Actor'
import { Film } from './Film'
import type { FilmAttributes, FilmCreationAttributes } from './Film'
import { Language } from './Language'
import type { LanguageAttributes, LanguageCreationAttributes } from './Language'
import { Category } from './Category'
import type { CategoryAttributes, CategoryCreationAttributes } from './Category'
import { Inventory } from './Inventory'
import type { InventoryAttributes, InventoryCreationAttributes } from './Inventory'
import { Store } from './Store'
import type { StoreAttributes, StoreCreationAttributes } from './Store'
import { Staff } from './Staff'
import type { StaffAttributes, StaffCreationAttributes } from './Staff'
import { Customer } from './Customer'
import type { CustomerAttributes, CustomerCreationAttributes } from './Customer'
import { Address } from './Address'
import type { AddressAttributes, AddressCreationAttributes } from './Address'
import { Rental } from './Rental'
import type { RentalAttributes, RentalCreationAttributes } from './Rental'
import { Payment } from './Payment'
import type { PaymentAttributes, PaymentCreationAttributes } from './Payment'
import { City } from './City'
import type { CityAttributes, CityCreationAttributes } from './City'
import { Country } from './Country'
import type { CountryAttributes, CountryCreationAttributes } from './Country'
import { FilmActor } from './FilmActor'
import type { FilmActorAttributes, FilmActorCreationAttributes } from './FilmActor'
import { FilmCategory } from './FilmCategory'
import type { FilmCategoryAttributes, FilmCategoryCreationAttributes } from './FilmCategory'
export {
Actor,
Film,
Language,
Category,
Inventory,
Store,
Staff,
Customer,
Address,
Rental,
Payment,
City,
Country,
FilmActor,
FilmCategory
}
export type {
ActorAttributes,
ActorCreationAttributes,
FilmAttributes,
FilmCreationAttributes,
LanguageAttributes,
LanguageCreationAttributes,
CategoryAttributes,
CategoryCreationAttributes,
InventoryAttributes,
InventoryCreationAttributes,
StoreAttributes,
StoreCreationAttributes,
StaffAttributes,
StaffCreationAttributes,
CustomerAttributes,
CustomerCreationAttributes,
AddressAttributes,
AddressCreationAttributes,
RentalAttributes,
RentalCreationAttributes,
PaymentAttributes,
PaymentCreationAttributes,
CityAttributes,
CityCreationAttributes,
CountryAttributes,
CountryCreationAttributes,
FilmActorAttributes,
FilmActorCreationAttributes,
FilmCategoryAttributes,
FilmCategoryCreationAttributes
}
export function initModels(sequelize: Sequelize) {
Actor.initModel(sequelize)
Film.initModel(sequelize)
Language.initModel(sequelize)
Category.initModel(sequelize)
Inventory.initModel(sequelize)
Store.initModel(sequelize)
Staff.initModel(sequelize)
Customer.initModel(sequelize)
Address.initModel(sequelize)
Rental.initModel(sequelize)
Payment.initModel(sequelize)
City.initModel(sequelize)
Country.initModel(sequelize)
FilmActor.initModel(sequelize)
FilmCategory.initModel(sequelize)
Actor.belongsToMany(Film, {
through: FilmActor,
foreignKey: 'actor_id',
otherKey: 'film_id',
onDelete: 'CASCADE'
})
Film.belongsTo(Language, {
foreignKey: 'language_id'
})
Film.belongsTo(Language, {
as: 'originalLanguage',
foreignKey: 'original_language_id'
})
Film.hasMany(Inventory, {
foreignKey: 'film_id'
})
Film.belongsToMany(Actor, {
through: FilmActor,
foreignKey: 'film_id',
otherKey: 'actor_id',
onDelete: 'CASCADE'
})
Film.belongsToMany(Category, {
through: FilmCategory,
foreignKey: 'film_id',
otherKey: 'category_id',
onDelete: 'CASCADE'
})
Language.hasMany(Film, {
foreignKey: 'language_id'
})
Language.hasMany(Film, {
as: 'originalLanguageFilms',
foreignKey: 'original_language_id'
})
Category.belongsToMany(Film, {
through: FilmCategory,
foreignKey: 'category_id',
otherKey: 'film_id',
onDelete: 'CASCADE'
})
Inventory.belongsTo(Film, {
foreignKey: 'film_id'
})
Inventory.belongsTo(Store, {
foreignKey: 'store_id'
})
Store.hasMany(Inventory, {
foreignKey: 'store_id'
})
Store.hasMany(Staff, {
foreignKey: 'store_id',
constraints: false
})
Store.hasMany(Customer, {
foreignKey: 'store_id'
})
Store.belongsTo(Staff, {
as: 'manager',
foreignKey: 'manager_staff_id',
constraints: false
})
Store.belongsTo(Address, {
foreignKey: 'address_id'
})
Staff.belongsTo(Store, {
foreignKey: 'store_id',
constraints: false
})
Staff.hasMany(Store, {
as: 'managedStores',
foreignKey: 'manager_staff_id',
constraints: false
})
Staff.belongsTo(Address, {
foreignKey: 'address_id'
})
Staff.hasMany(Rental, {
foreignKey: 'staff_id'
})
Staff.hasMany(Payment, {
foreignKey: 'staff_id'
})
Customer.belongsTo(Store, {
foreignKey: 'store_id'
})
Customer.belongsTo(Address, {
foreignKey: 'address_id'
})
Customer.hasMany(Rental, {
foreignKey: 'customer_id'
})
Customer.hasMany(Payment, {
foreignKey: 'customer_id'
})
Address.belongsTo(City, {
foreignKey: 'city_id'
})
Address.hasOne(Customer, {
foreignKey: 'address_id'
})
Address.hasOne(Staff, {
foreignKey: 'address_id'
})
Address.hasOne(Store, {
foreignKey: 'address_id'
})
Rental.belongsTo(Inventory, {
foreignKey: 'inventory_id'
})
Rental.belongsTo(Customer, {
foreignKey: 'customer_id'
})
Rental.belongsTo(Staff, {
foreignKey: 'staff_id'
})
Rental.hasMany(Payment, {
foreignKey: 'rental_id'
})
Payment.belongsTo(Customer, {
foreignKey: 'customer_id'
})
Payment.belongsTo(Staff, {
foreignKey: 'staff_id'
})
Payment.belongsTo(Rental, {
foreignKey: 'rental_id'
})
City.belongsTo(Country, {
foreignKey: 'country_id'
})
City.hasMany(Address, {
foreignKey: 'city_id'
})
Country.hasMany(City, {
foreignKey: 'country_id'
})
FilmActor.belongsTo(Film, {
foreignKey: 'film_id'
})
FilmActor.belongsTo(Actor, {
foreignKey: 'actor_id'
})
FilmCategory.belongsTo(Film, {
foreignKey: 'film_id'
})
FilmCategory.belongsTo(Category, {
foreignKey: 'category_id'
})
return {
Actor,
Film,
Language,
Category,
Inventory,
Store,
Staff,
Customer,
Address,
Rental,
Payment,
City,
Country,
FilmActor,
FilmCategory
}
}