5 Video Rental Example Schema
(require plisqin/examples/video-rental-schema) | |
package: plisqin |
This section documents an example database schema that models a brick-and-mortar video rental store. Each table has an explanation of what it means. Joins and fields typically just show the code.
This diagram shows the database model.
5.1 Tables
5.2 Singular Relationships
procedure
(Account-of/s x) → Account?
x : any/c
(field-cases (Account-of/s x) [(Customer? x) (join a (Account) (join-on a".AccountId = "x".AccountId"))] [(Checkout? x) (Account-of/s (Customer-of/s x))] [(Rental? x) (Account-of/s (Checkout-of/s x))] [(Account? x) x])
procedure
(Checkout-of/s x) → Checkout?
x : any/c
(field-cases (Checkout-of/s x) [(Checkout? x) x] [(Rental? x) (join c (Checkout) (join-on c".CheckoutId = "x".CheckoutId"))])
(field-cases (Copy-of/s x) [(Rental? x) (join c (Copy) (join-on c".CopyId = "x".CopyId"))] [(Copy? x) x])
procedure
(Customer-of/s x) → Customer?
x : any/c
(field-cases (Customer-of/s x) [(Customer? x) x] [(Rental? x) (Customer-of/s (Checkout-of/s x))] [(Checkout? x) (join c (Customer) (join-on c".CustomerId = "x".CustomerId"))])
(field-cases (Item-of/s x) [(Copy? x) (join i (Item) (join-on i".ItemId = "x".ItemId"))] [(Rental? x) (Item-of/s (Copy-of/s x))] [(Item? x) x])
5.3 Plural Relationships
procedure
(Checkouts-of/p x) → Checkout?
x : any/c
(field-cases (Checkouts-of/p x) [(Employee? x) (join c (Checkout) (join-on c".EmployeeId = "x".EmployeeId"))] [(Store? x) (join c (Checkout) (join-on c".StoreId = "x".StoreId"))])
procedure
(Copies-of/p x) → Copy?
x : any/c
(field-cases (Copies-of/p x) [(Item? x) (join c (Copy) (join-on c".ItemId = "x".ItemId"))])
procedure
(Genres-of/p x) → Genre?
x : any/c
(field-cases (Genres-of/p x) [(Item? x) (join g (Genre) (join-on g".GenreId = "(ItemGenres-of/p x)".GenreId"))] [(or (Copy? x) (Rental? x)) (Genres-of/p (Item-of/s x))])
procedure
(ItemGenres-of/p x) → ItemGenre?
x : any/c
(field-cases (ItemGenres-of/p x) [(Item? x) (join ig (ItemGenre) (join-on ig".ItemId = "x".ItemId"))] [(Genre? x) (join ig (ItemGenre) (join-on ig".GenreId = "x".GenreId"))] [(or (Copy? x) (Rental? x)) (ItemGenres-of/p (Item-of/s x))])
procedure
(Store-of/s x) → Store?
x : any/c
(field-cases (Store-of/s x) [(or (Checkout? x) (Employee? x)) (join s (Store) (join-on s".StoreId = "x".StoreId"))] [(or (Rental? x) (Copy? x)) (Store-of/s (Checkout-of/s x))] [(Store? x) x])
5.4 Grouped Relationships
procedure
(Copies-of/g x) → Copy?
x : any/c
(field-cases (Copies-of/g x) [(Item? x) (join c (Copy) (group-by (ItemId c)) (join-on (ItemId c)" = "(ItemId x)))])
procedure
(Rentals-of/g x) → Rental?
x : any/c
(field-cases (Rentals-of/g x) [(Customer? x) (join r (Rental) (group-by (CustomerId r)) (join-on (CustomerId r)" = "(CustomerId x)))] [(Copy? x) (join r (Rental) (group-by (CopyId r)) (join-on (CopyId r)" = "(CopyId x)))] [(Item? x) (join r (Rental) (group-by (ItemId r)) (join-on (ItemId r)" = "(ItemId x)))])
procedure
(grouped-Rentals-of x) → Rental?
x : any/c
5.5 Fields
(field-cases (Address x) [(Store? x) (scalar x".Address")])
procedure
(CheckoutTime x) → fragment?
x : any/c
(field-cases (CheckoutTime x) [(Checkout? x) (scalar x".CheckoutTime")] [(Rental? x) (CheckoutTime (Checkout-of/s x))])
(field-cases (CopyId x) [(or (Copy? x) (Rental? x)) (scalar x".CopyId")] [(Item? x) (CopyId (Copy-of/s x))])
procedure
(CustomerBirthDate x) → fragment?
x : any/c
(field-cases (CustomerBirthDate x) [(Customer? x) (scalar x".CustomerBirthDate")] [(or (Checkout? x) (Rental? x)) (CustomerBirthDate (Customer-of/s x))])
procedure
(CustomerId x) → fragment?
x : any/c
(field-cases (CustomerId x) [(or (Customer? x) (Checkout? x)) (scalar x".CustomerId")] [(Rental? x) (CustomerId (Checkout-of/s x))])
(field-cases (ItemId x) [(or (Item? x) (Copy? x)) (scalar x".ItemId")] [(Rental? x) (ItemId (Copy-of/s x))])
procedure
(ItemTypeId x) → fragment?
x : any/c
(field-cases (ItemTypeId x) [(or (ItemType? x) (Item? x)) (scalar x".ItemTypeId")] [(or (Copy? x) (Rental? x)) (ItemTypeId (Item-of/s x))])
procedure
(ReleaseDate x) → fragment?
x : any/c
(field-cases (ReleaseDate x) [(Item? x) (scalar x".ReleaseDate")] [(or (Copy? x) (Rental? x)) (ReleaseDate (Item-of/s x))])
(field-cases (RentalId x) [(Rental? x) (scalar x".RentalId")])
(field-cases (StoreId x) [(Store? x) (scalar x".StoreId")] [(or (Rental? x) (Checkout? x)) (StoreId (Store-of/s x))])