question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Heads up: Composite Types

See original GitHub issue

We will soon release a new feature, that is relevant for ERD generation: Composite Types. They are pretty much like Models, but represent Embedded Documents for MongoDB for example:

This is what the underlying data looks like: https://docs.atlas.mongodb.com/sample-data/sample-airbnb/

And this the schema:

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["mongoDb"]
}

datasource db {
  provider = "mongodb"
  url      = "mongodb+srv://us...godb.net/sample_airbnb"
}

type ListingsAndReviewsAddress {
  country         String
  country_code    String
  government_area String
  location        ListingsAndReviewsAddressLocation
  market          String
  street          String
  suburb          String
}

type ListingsAndReviewsAddressLocation {
  coordinates       Float[]
  is_location_exact Boolean
  type              String
}

type ListingsAndReviewsAvailability {
  availability_30  Int
  availability_365 Int
  availability_60  Int
  availability_90  Int
}

type ListingsAndReviewsHost {
  host_about                String
  host_has_profile_pic      Boolean
  host_id                   String
  host_identity_verified    Boolean
  host_is_superhost         Boolean
  host_listings_count       Int
  host_location             String
  host_name                 String
  host_neighbourhood        String
  host_picture_url          String
  host_response_rate        Int?
  host_response_time        String?
  host_thumbnail_url        String
  host_total_listings_count Int
  host_url                  String
  host_verifications        String[]
}

type ListingsAndReviewsImages {
  medium_url     String
  picture_url    String
  thumbnail_url  String
  xl_picture_url String
}

type ListingsAndReviewsReviewScores {
  review_scores_accuracy      Int?
  review_scores_checkin       Int?
  review_scores_cleanliness   Int?
  review_scores_communication Int?
  review_scores_location      Int?
  review_scores_rating        Int?
  review_scores_value         Int?
}

type ListingsAndReviewsReviews {
  id            String   @map("_id")
  comments      String?
  date          DateTime @db.Date
  listing_id    String
  reviewer_id   String
  reviewer_name String
}

model listingsAndReviews {
  id                    String                         @id @map("_id")
  access                String
  accommodates          Int
  address               ListingsAndReviewsAddress
  amenities             String[]
  availability          ListingsAndReviewsAvailability
  bathrooms             Decimal?
  bed_type              String
  bedrooms              Int?
  beds                  Int?
  calendar_last_scraped DateTime                       @db.Date
  cancellation_policy   String
  cleaning_fee          Decimal?
  description           String
  extra_people          Decimal
  first_review          DateTime?                      @db.Date
  guests_included       Decimal
  host                  ListingsAndReviewsHost
  house_rules           String
  images                ListingsAndReviewsImages
  interaction           String
  last_review           DateTime?                      @db.Date
  last_scraped          DateTime                       @db.Date
  listing_url           String
  maximum_nights        String
  minimum_nights        String
  monthly_price         Decimal?
  name                  String
  neighborhood_overview String
  notes                 String
  number_of_reviews     Int
  price                 Decimal
  property_type         String
  review_scores         ListingsAndReviewsReviewScores
  reviews               ListingsAndReviewsReviews[]
  reviews_per_month     Int?
  room_type             String
  security_deposit      Decimal?
  space                 String
  summary               String
  transit               String
  weekly_price          Decimal?

  @@index([property_type, room_type, beds], map: "property_type_1_room_type_1_beds_1")
  @@index([name], map: "name_1")
}

So we have one model, that then uses quite a few type in place where there could also be a Json field.

It probably makes sense to display these composite types as normal “tables” via “relations” - 1-1 or 1-n (lists) are possible. They don’t have a primary key and can not include relations, and their usage is also not via @relation but more like a type.

Let me know if you have any questions.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
janpiocommented, Feb 23, 2022

I wanted to visualize some of our schemas with composite types, so I spent a few minutes and implemented a first quick and dirty version of this: https://github.com/keonik/prisma-erd-generator/pull/71

The schemas posted above, in the same order as they appear:

sample-airbnb: image

sample_mflix: image

sample_restaurants: image

sample_supplies: image

sample_training: image (This one is buggy somehow)

sample_weatherdata: image image image image image

They are all missing the normal relations between models because these can not be introspected in MongoDB and have to be added by hand - which I have not done for these yet. Still nice results I think.

1reaction
keonikcommented, Feb 18, 2022

It looks pretty similar to model at first glance, just doesn’t have the explicit @relation attached. Thanks for the heads up! If I get some time I’ll play around with what is here to see if I can get it rendered correctly

Read more comments on GitHub >

github_iconTop Results From Across the Web

Heads up on Heads Up Composite bumpers...
Heads up on Heads Up Composite bumpers. ... But those guys do not strike me as that type of people. ... Would Heads...
Read more >
10 Surprising Examples of Composite Materials
1. Mud Bricks · 2. Wood · 3. Fiberglass · 4. Translucent Concrete · 5. Absorbent Concrete · 6. Kevlar · 7. Carbon...
Read more >
Composite Flowers - Backyard Nature
Heads composed of both disc and ray flowers, with disc flowers tightly packed in the head's "eye," while enlarged ray flowers function as...
Read more >
What is a Composite Material? (A Definitive Guide) - TWI Global
A composite material is a combination of two materials with different physical and chemical properties. When they are combined they create a material...
Read more >
Lay-up Process - an overview | ScienceDirect Topics
The variety of fabrication techniques available for FRP composites – wet lay-up process, pultrusion filament winding, Resin transfer moulding (Hollaway and Head ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found