Skip to content

Commit

Permalink
is and isNot (prisma#1892)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhwelander authored Jun 17, 2021
1 parent c308413 commit e8dd3db
Show file tree
Hide file tree
Showing 40 changed files with 404 additions and 304 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,11 @@ const user = await prisma.user.update({

## Relation filters

Prisma Client provides the [`some`](../../../reference/api-reference/prisma-client-reference#some), [`every`](../../../reference/api-reference/prisma-client-reference#every), and [`none`](../../../reference/api-reference/prisma-client-reference#none) options to filter records by the properties of _related_ records. For example:
### Filter on "-to-many" relations

Prisma Client provides the [`some`](../../../reference/api-reference/prisma-client-reference#some), [`every`](../../../reference/api-reference/prisma-client-reference#every), and [`none`](../../../reference/api-reference/prisma-client-reference#none) options to filter records by the properties of related records on the "-to-many" side of the relation. For example, filtering users based on properties of their posts.

For example:

| Requirement | Query option to use |
| --------------------------------------------------------------------------------- | ----------------------------------- |
Expand Down Expand Up @@ -1127,6 +1131,33 @@ const users = await prisma.user.findMany({
})
```

### Filter on "-to-one" relations

Prisma Client provides the [`is`](../../../reference/api-reference/prisma-client-reference#is) and [`isNot`](../../../reference/api-reference/prisma-client-reference#isNot) options to filter records by the properties of related records on the "-to-one" side of the relation. For example, filtering posts based on properties of their author.

For example, the following query returns `Post` records that meet the following criteria:

* Author's name is not Bob
* Author is older than 40

```ts
const users = await prisma.post.findMany({
where: {
author: {
isNot: {
name: "Bob"
},
is: {
age: {
gt: 40
}
}
}
}
},
})
```

### Filter on presence of related records

[Filtering by count of relations](https://github.com/prisma/prisma/issues/3821) is not yet supported - however, you can filter on whether a record has any related records at all. For example, the following query uses `none` to return all users that have zero posts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3873,6 +3873,65 @@ const result = await prisma.user.findMany({
}
```
### <inlinecode>is</inlinecode>
Returns all records where related record matches filtering criteria (for example, user's name `is` Bob).
#### Reference
```ts file=index.d.ts highlight=2;normal
export type UserRelationFilter = {
is?: UserWhereInput | null
isNot?: UserWhereInput | null
}
```
#### Examples
##### Get all `Post` records where user's name is `"Bob"`
```ts
const result = await prisma.post.findMany({
where: {
user: {
is: {
name: "Bob"
},
}
}
}
```
### <inlinecode>isNot</inlinecode>
Returns all records where related record matches filtering criteria (for example, user's name `isNot` Bob).
#### Reference
```ts file=index.d.ts highlight=3;normal
export type UserRelationFilter = {
is?: UserWhereInput | null
isNot?: UserWhereInput | null
}
```
#### Examples
##### Get all `Post` records where user's name is NOT `"Bob"`
```ts
const result = await prisma.post.findMany({
where: {
user: {
isNot: {
name: "Bob"
},
}
}
}
```
## Scalar list methods
### Reference
Expand Down
4 changes: 2 additions & 2 deletions src/components/button/AccentButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export enum AccentColor {
}

export const AccentButton = styled(Button)<{ color: AccentColor }>`
background: ${p => colorForOption(p.color)};
background: ${(p) => colorForOption(p.color)};
color: ${theme.colors.white};
&:hover {
background: ${p => hoverColorForOption(p.color)};
background: ${(p) => hoverColorForOption(p.color)};
}
`

Expand Down
6 changes: 3 additions & 3 deletions src/components/button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ const radiusForSize = (size?: ButtonSize) => {
}

const Base = styled.a<{ size?: ButtonSize }>`
font-size: ${p => fontSizeForSize(p.size)};
font-size: ${(p) => fontSizeForSize(p.size)};
font-weight: 600;
padding: ${p => paddingForSize(p.size)};
padding: ${(p) => paddingForSize(p.size)};
display: inline-block;
border: none;
text-align: left;
border-radius: ${p => radiusForSize(p.size)};
border-radius: ${(p) => radiusForSize(p.size)};
line-height: 1.5;
cursor: pointer;
text-decoration: none;
Expand Down
6 changes: 3 additions & 3 deletions src/components/customMdx/admonition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const AdmonitionWrapper = styled.span<{ type?: string }>`
font-size: 16px;
line-height: 24px;
color: ${theme.colors.gray600} !important;
padding-left: ${p => (p.type === 'alert' ? '3rem' : '1.5rem')};
padding-left: ${(p) => (p.type === 'alert' ? '3rem' : '1.5rem')};
padding-bottom: 8px;
padding-bottom: 8px;
margin: 2rem 0px;
Expand All @@ -53,7 +53,7 @@ const AdmonitionWrapper = styled.span<{ type?: string }>`
width: 8px;
height: 100%;
left: 0px;
background: ${p => (p.type ? colorMap[p.type] : colorMap['info'])} !important;
background: ${(p) => (p.type ? colorMap[p.type] : colorMap['info'])} !important;
border-radius: 5px;
}
Expand All @@ -69,7 +69,7 @@ const AdmonitionWrapper = styled.span<{ type?: string }>`
display: flex;
justify-content: center;
padding: 12px 0;
background: ${p => (p.type ? colorMap[p.type] : colorMap['info'])} !important;
background: ${(p) => (p.type ? colorMap[p.type] : colorMap['info'])} !important;
border-radius: 5px;
}
Expand Down
14 changes: 7 additions & 7 deletions src/components/customMdx/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ export const ButtonWrapper = withProps<ButtonProps>(styled.a)`
margin-right: 10px;
display: inline-flex;
align-items: center;
${p => (p.block ? 'width: 100%;' : '')}
${(p) => (p.block ? 'width: 100%;' : '')}
border: none;
text-decoration: none;
height: 40px;
font-size: ${p => p.theme.fontSizes[16]};
font-size: ${(p) => p.theme.fontSizes[16]};
box-sizing: border-box;
outline: none;
opacity: ${p => (p.disabled ? '0.2' : 1)};
opacity: ${(p) => (p.disabled ? '0.2' : 1)};
text-transform: uppercase;
letter-spacing: 0.4px;
background: ${p => backgroundColorMap[p.color || 'green']};
color: ${p => colorMap[p.color || 'green']} !important;
background: ${(p) => backgroundColorMap[p.color || 'green']};
color: ${(p) => colorMap[p.color || 'green']} !important;
line-height: 1;
font-size: 14px;
font-weight: 700;
cursor: ${p => (p.disabled ? 'default' : 'pointer')};
pointer-events: ${p => (p.disabled ? 'none' : 'all')};
cursor: ${(p) => (p.disabled ? 'default' : 'pointer')};
pointer-events: ${(p) => (p.disabled ? 'none' : 'all')};
border-radius: 6px;
transition: color 150ms ease 0s, background 150ms ease 0s, transform 100ms ease 0s;
white-space: nowrap;
Expand Down
20 changes: 10 additions & 10 deletions src/components/customMdx/code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,13 @@ const Code = ({ children, className, ...props }: PreCodeProps) => {
export default Code

const CodeWrapper = styled.div`
margin-top: ${p => p.theme.space[24]};
margin-bottom: ${p => p.theme.space[24]};
margin-top: ${(p) => p.theme.space[24]};
margin-bottom: ${(p) => p.theme.space[24]};
.file {
font-weight: 600;
color: ${p => p.theme.colors.gray600};
font-size: ${p => p.theme.fontSizes[14]};
font-family: ${p => p.theme.fonts.text};
color: ${(p) => p.theme.colors.gray600};
font-size: ${(p) => p.theme.fontSizes[14]};
font-family: ${(p) => p.theme.fonts.text};
margin-bottom: 0.5rem;
}
`
Expand All @@ -225,13 +225,13 @@ const AbsoluteCopyButton = styled.div`
z-index: 2;
> div {
right: -${p => p.theme.space[8]};
right: -${(p) => p.theme.space[8]};
top: -6px;
}
`

const Pre = styled.pre`
margin-top: ${p => p.theme.space[32]};
margin-top: ${(p) => p.theme.space[32]};
text-align: left;
margin: 0 0 16px 0;
padding: 2rem 1rem 1rem 1rem;
Expand All @@ -244,16 +244,16 @@ const Line = styled.div`

const LineNo = styled.span`
font-weight: 500;
line-height: ${p => p.theme.space[24]};
color: ${p => p.theme.colors.gray400};
line-height: ${(p) => p.theme.space[24]};
color: ${(p) => p.theme.colors.gray400};
display: inline-block;
text-align: right;
user-select: none;
width: 24px;
`

const LineContent = styled.span`
padding: 0 ${p => p.theme.space[16]};
padding: 0 ${(p) => p.theme.space[16]};
&.break-words {
display: inline-table;
white-space: break-spaces;
Expand Down
4 changes: 2 additions & 2 deletions src/components/customMdx/codeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ const Tabs = styled.div`
display: flex;
.tab {
margin-right: 10px;
color: ${p => p.theme.colors.gray600};
color: ${(p) => p.theme.colors.gray600};
cursor: pointer;
}
.tab.active {
font-weight: 600;
color: ${p => p.theme.colors.gray900};
color: ${(p) => p.theme.colors.gray900};
}
`
const Wrapper = styled.div`
Expand Down
2 changes: 1 addition & 1 deletion src/components/customMdx/codeWithResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const Wrapper = styled.div`
}
.token.punctuation {
color: ${p => p.theme.colors.gray500} !important;
color: ${(p) => p.theme.colors.gray500} !important;
}
border-radius: 0px 0px 8px 8px;
Expand Down
14 changes: 7 additions & 7 deletions src/components/customMdx/collapsible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const CollapseBox = ({ children, ...props }: CollapseProps) => {
export default CollapseBox

const Wrapper = styled.div`
margin-bottom: ${p => p.theme.space[16]};
margin-bottom: ${(p) => p.theme.space[16]};
`

const Tab = styled.div`
Expand All @@ -42,11 +42,11 @@ const Tab = styled.div`
width: 8px;
height: 100%;
left: 0px;
background: ${p => p.theme.colors.gray100};
border-radius: ${p => p.theme.radii.small};
background: ${(p) => p.theme.colors.gray100};
border-radius: ${(p) => p.theme.radii.small};
}
p {
margin-top: ${p => p.theme.space[8]};
margin-top: ${(p) => p.theme.space[8]};
}
`

Expand All @@ -56,14 +56,14 @@ const Label = styled.label`
color: #0c344b;
font-weight: 600;
line-height: 1.5;
padding-left: ${p => p.theme.space[32]};
padding-left: ${(p) => p.theme.space[32]};
cursor: pointer;
`

const TabContent = styled.div`
max-height: 0;
overflow: hidden;
color: ${p => p.theme.colors.gray800};
color: ${(p) => p.theme.colors.gray800};
transition: max-height 0.35s, padding 0.35s;
padding-left: 36px;
padding-bottom: 0;
Expand All @@ -75,7 +75,7 @@ const Input = styled.input`
z-index: -1;
&:checked ~ .tab-content {
max-height: 2000px;
padding-bottom: ${p => p.theme.space[8]};
padding-bottom: ${(p) => p.theme.space[8]};
}
`

Expand Down
2 changes: 1 addition & 1 deletion src/components/customMdx/copy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const CopyButton = ({ text, children }: CopyButtonProps) => {
export default CopyButton

const CopyComponent = styled.div`
font-family: ${p => p.theme.fonts.text};
font-family: ${(p) => p.theme.fonts.text};
& {
position: relative;
cursor: pointer;
Expand Down
6 changes: 3 additions & 3 deletions src/components/customMdx/fileWithIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ const FileNameWrapper = styled.span`
display: inline-flex;
align-items: center;
svg {
margin-right: ${p => p.theme.space[8]};
margin-right: ${(p) => p.theme.space[8]};
}
@media (max-width: ${p => p.theme.breakpoints.tablet}) {
font-size: ${p => p.theme.fontSizes[14]};
@media (max-width: ${(p) => p.theme.breakpoints.tablet}) {
font-size: ${(p) => p.theme.fontSizes[14]};
}
`

Expand Down
12 changes: 6 additions & 6 deletions src/components/customMdx/parallelBlocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ const Block = styled.div`
}
.blockHeading {
font-weight: 600;
font-size: ${p => p.theme.fontSizes[14]};
font-size: ${(p) => p.theme.fontSizes[14]};
svg {
margin-right: ${p => p.theme.space[8]};
margin-right: ${(p) => p.theme.space[8]};
}
}
Expand All @@ -43,21 +43,21 @@ const Block = styled.div`
}
}
@media (max-width: ${p => p.theme.breakpoints.tablet}) and (min-width: 0px) {
@media (max-width: ${(p) => p.theme.breakpoints.tablet}) and (min-width: 0px) {
.pre-highlight {
margin: 0;
}
&:first-of-type .pre-highlight {
margin-right: 0;
margin-left: -${p => p.theme.space[24]};
margin-left: -${(p) => p.theme.space[24]};
}
&:last-of-type .pre-highlight {
margin-left: 0;
margin-right: -${p => p.theme.space[24]};
margin-right: -${(p) => p.theme.space[24]};
}
}
`
const Wrapper = styled.div`
display: flex;
margin-top: ${p => p.theme.space[32]};
margin-top: ${(p) => p.theme.space[32]};
`
Loading

0 comments on commit e8dd3db

Please sign in to comment.