IssueRaiser

Support for a Union type

## Problem Unions data types are handy in features like feeds. Right now it's difficult to model unions in Prisma and it would be great if we could make this feature higher-level. You'll also find community use cases in [this thread](https://github.com/prisma/prisma/issues/253#issuecomment-588589934). ## Possible solution Facebook's feed is a good example. The feed has Videos, Photos and Posts. **Modeled in Typescript** ```typescript type Activity = Video | Photo | Message type Video = { type: 'video' url: string media: 'webm' | 'mp4' } type Photo = { type: 'photo' width: number height: number } type Post = { type: 'post' message: string } ``` **Modeled in Postgres** ```sql create sequence bigserial activity_id; create table videos ( id activity_id primary key, url text not null, media text not null ) create table photos ( id activity_id primary key, width int, height int ) create table posts ( id activity_id primary key, message text ) ``` ## Alternatives There are lots of alternative table inheritance schemes. We'd need to weigh the pros and cons of each.

Posted by matthewmueller on May 18, 2020, 3:37 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,500 issues0 comments

ux (Software)

Support for a Union type

matthewmuellerMay 18, 2020, 3:37 PM

## Problem Unions data types are handy in features like feeds. Right now it's difficult to model unions in Prisma and it would be great if we could make this feature higher-level. You'll also find community use cases in [this thread](https://github.com/prisma/prisma/issues/253#issuecomment-588589934). ## Possible solution Facebook's feed is a good example. The feed has Videos, Photos and Posts. **Modeled in Typescript** ```typescript type Activity = Video | Photo | Message type Video = { type: 'video' url: string media: 'webm' | 'mp4' } type Photo = { type: 'photo' width: number height: number } type Post = { type: 'post' message: string } ``` **Modeled in Postgres** ```sql create sequence bigserial activity_id; create table videos ( id activity_id primary key, url text not null, media text not null ) create table photos ( id activity_id primary key, width int, height int ) create table posts ( id activity_id primary key, message text ) ``` ## Alternatives There are lots of alternative table inheritance schemes. We'd need to weigh the pros and cons of each.

Comments (0)

No comments yet. Start the discussion.

Comment on this issue