// SIGNED-SOURCE: /** * AUTO-GENERATED FILE * Do not modify. Update your schema and re-generate for changes. */ import Track from "../Track.js"; import { default as s } from "./TrackSpec.js"; import { P } from "@aphro/runtime-ts"; import { UpdateMutationBuilder } from "@aphro/runtime-ts"; import { CreateMutationBuilder } from "@aphro/runtime-ts"; import { DeleteMutationBuilder } from "@aphro/runtime-ts"; import { makeSavable } from "@aphro/runtime-ts"; import { modelGenMemo } from "@aphro/runtime-ts"; import { Node } from "@aphro/runtime-ts"; import { NodeSpecWithCreate } from "@aphro/runtime-ts"; import { SID_of } from "@aphro/runtime-ts"; import TrackQuery from "./TrackQuery.js"; import { Context } from "@aphro/runtime-ts"; import AlbumQuery from "./AlbumQuery.js"; import AlbumSpec from "./AlbumSpec.js"; import MediaTypeQuery from "./MediaTypeQuery.js"; import MediaTypeSpec from "./MediaTypeSpec.js"; import GenreQuery from "./GenreQuery.js"; import GenreSpec from "./GenreSpec.js"; import InvoiceLineQuery from "./InvoiceLineQuery.js"; import InvoiceLine from "../InvoiceLine.js"; import Album from "../Album.js"; import MediaType from "../MediaType.js"; import Genre from "../Genre.js"; export type Data = { id: SID_of; name: string; albumId: SID_of | null; mediaTypeId: SID_of; genreId: SID_of | null; composer: string | null; milliseconds: number; bytes: number | null; unitPrice: number; }; // @Sealed(Track) export default abstract class TrackBase extends Node { readonly spec = s as unknown as NodeSpecWithCreate; get id(): SID_of { return this.data.id as unknown as SID_of; } get name(): string { return this.data.name; } get albumId(): SID_of | null { return this.data.albumId; } get mediaTypeId(): SID_of { return this.data.mediaTypeId; } get genreId(): SID_of | null { return this.data.genreId; } get composer(): string | null { return this.data.composer; } get milliseconds(): number { return this.data.milliseconds; } get bytes(): number | null { return this.data.bytes; } get unitPrice(): number { return this.data.unitPrice; } queryAlbum(): AlbumQuery { if (this.albumId == null) { return AlbumQuery.empty(this.ctx); } return AlbumQuery.fromId(this.ctx, this.albumId); } queryMediaType(): MediaTypeQuery { return MediaTypeQuery.fromId(this.ctx, this.mediaTypeId); } queryGenre(): GenreQuery { if (this.genreId == null) { return GenreQuery.empty(this.ctx); } return GenreQuery.fromId(this.ctx, this.genreId); } queryInvoiceLines(): InvoiceLineQuery { return InvoiceLineQuery.create(this.ctx).whereTrackId( P.equals(this.id as any) ); } async genAlbum(): Promise { const existing = this.ctx.cache.get( this.albumId, AlbumSpec.storage.db, AlbumSpec.storage.tablish ); if (existing != null) { return existing; } return await this.queryAlbum().genOnlyValue(); } async genMediaType(): Promise { const existing = this.ctx.cache.get( this.mediaTypeId, MediaTypeSpec.storage.db, MediaTypeSpec.storage.tablish ); if (existing != null) { return existing; } return await this.queryMediaType().genxOnlyValue(); } async genGenre(): Promise { const existing = this.ctx.cache.get( this.genreId, GenreSpec.storage.db, GenreSpec.storage.tablish ); if (existing != null) { return existing; } return await this.queryGenre().genOnlyValue(); } static queryAll(ctx: Context): TrackQuery { return TrackQuery.create(ctx); } static genx = modelGenMemo( "chinook", "track", (ctx: Context, id: SID_of): Promise => this.queryAll(ctx).whereId(P.equals(id)).genxOnlyValue() ); static gen = modelGenMemo( "chinook", "track", // @ts-ignore #43 (ctx: Context, id: SID_of): Promise => this.queryAll(ctx).whereId(P.equals(id)).genOnlyValue() ); update(data: Partial) { return makeSavable( this.ctx, new UpdateMutationBuilder(this.ctx, this.spec, this) .set(data) .toChangesets()[0] ); } static create(ctx: Context, data: Partial) { return makeSavable( ctx, new CreateMutationBuilder(ctx, s).set(data).toChangesets()[0] ); } delete() { return makeSavable( this.ctx, new DeleteMutationBuilder(this.ctx, this.spec, this).toChangesets()[0] ); } }