-
Notifications
You must be signed in to change notification settings - Fork 6
[EdgeDB] Pin queries #3208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[EdgeDB] Pin queries #3208
Changes from 1 commit
d82be69
03125c1
4292a6d
e73bcae
cf457b4
918e6d5
9d17f3e
f257881
1b559a8
abfb1d0
32e8048
0f29097
733b71d
65608a6
10b4e47
2e87064
6bb689c
661dfe1
1433853
8d28850
2731c01
507be09
5492495
026a699
b1348f7
d3168cb
ee8ac45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,83 @@ | ||||||||||||
import { Inject, Injectable } from '@nestjs/common'; | ||||||||||||
import { DateTime } from 'luxon'; | ||||||||||||
import { ID, PublicOf, Session } from '~/common'; | ||||||||||||
import { Client } from '~/core/edgedb'; | ||||||||||||
import { PinRepository } from './pin.repository'; | ||||||||||||
|
||||||||||||
@Injectable() | ||||||||||||
export class PinEdgeDBRepository implements PublicOf<PinRepository> { | ||||||||||||
constructor(@Inject(Client) private readonly client: Client) {} | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
async isPinned(id: ID, session: Session): Promise<boolean> { | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @CarsonF - Since the schema itself defines a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The select (<Pinnable><uuid>$id).pinned Or with obj := <Pinnable><uuid>$id
select obj.pinned |
||||||||||||
const res: boolean | null = await this.client.querySingle( | ||||||||||||
` | ||||||||||||
select exists( | ||||||||||||
select BaseNode { | ||||||||||||
id, | ||||||||||||
pinned_by := .<pinned[is User]> { | ||||||||||||
id | ||||||||||||
} | ||||||||||||
} | ||||||||||||
filter .id = <uuid>$id | ||||||||||||
and .pinned_by.id = <uuid>$userId | ||||||||||||
); | ||||||||||||
`, | ||||||||||||
{ | ||||||||||||
id, | ||||||||||||
userId: session.userId, | ||||||||||||
}, | ||||||||||||
); | ||||||||||||
|
||||||||||||
return Boolean(res); | ||||||||||||
} | ||||||||||||
|
||||||||||||
async add(id: ID, session: Session): Promise<void> { | ||||||||||||
const createdAt = DateTime.local(); | ||||||||||||
|
||||||||||||
await this.client.query( | ||||||||||||
` | ||||||||||||
with BaseNode := ( | ||||||||||||
select BaseNode | ||||||||||||
filter .id = <uuid>$id | ||||||||||||
), | ||||||||||||
User := ( | ||||||||||||
select User | ||||||||||||
filter .id = <uuid>$userId | ||||||||||||
) | ||||||||||||
insert PinnedRelation { | ||||||||||||
node := BaseNode, | ||||||||||||
user := User, | ||||||||||||
createdAt := <datetime>$createdAt | ||||||||||||
} | ||||||||||||
unless conflict on (.node, .user) | ||||||||||||
`, | ||||||||||||
{ | ||||||||||||
id, | ||||||||||||
userId: session.userId, | ||||||||||||
createdAt: createdAt.toJSDate(), | ||||||||||||
}, | ||||||||||||
); | ||||||||||||
} | ||||||||||||
|
||||||||||||
async remove(id: ID, session: Session): Promise<void> { | ||||||||||||
await this.client.query( | ||||||||||||
` | ||||||||||||
with BaseNode := ( | ||||||||||||
select BaseNode | ||||||||||||
filter .id = <uuid>$id | ||||||||||||
), | ||||||||||||
User := ( | ||||||||||||
select User | ||||||||||||
filter .id = <uuid>$userId | ||||||||||||
) | ||||||||||||
delete PinnedRelation | ||||||||||||
filter .node = BaseNode | ||||||||||||
and .user = User | ||||||||||||
`, | ||||||||||||
{ | ||||||||||||
id, | ||||||||||||
userId: session.userId, | ||||||||||||
}, | ||||||||||||
); | ||||||||||||
} | ||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { splitDb } from '~/core'; | ||
import { PinEdgeDBRepository } from './pin.edgedb.repository'; | ||
import { PinRepository } from './pin.repository'; | ||
import { PinResolver } from './pin.resolver'; | ||
import { PinService } from './pin.service'; | ||
|
||
@Module({ | ||
providers: [PinResolver, PinService, PinRepository], | ||
providers: [ | ||
PinResolver, | ||
PinService, | ||
splitDb(PinRepository, PinEdgeDBRepository), | ||
], | ||
exports: [PinService], | ||
}) | ||
export class PinModule {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't needed since
Pinnable
isn't aResource
.