mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2025-08-31 22:50:43 +00:00
better upsert query
the default `.upsert` method would clobber the `id`
This commit is contained in:
parent
3aa5ec713c
commit
4651edbc4e
1 changed files with 17 additions and 12 deletions
|
@ -27,7 +27,9 @@ export class RegistryApiService {
|
|||
public async set(userId: MiUser['id'], domain: string | null, scope: string[], key: string, value: any) {
|
||||
// TODO: 作成できるキーの数を制限する
|
||||
|
||||
await this.registryItemsRepository.upsert({
|
||||
await this.registryItemsRepository.createQueryBuilder('item')
|
||||
.insert()
|
||||
.values({
|
||||
id: this.idService.gen(),
|
||||
updatedAt: new Date(),
|
||||
userId: userId,
|
||||
|
@ -35,10 +37,13 @@ export class RegistryApiService {
|
|||
scope: scope,
|
||||
key: key,
|
||||
value: value,
|
||||
}, {
|
||||
conflictPaths: ['userId', 'key', 'scope', 'domain'],
|
||||
upsertType: 'on-conflict-do-update',
|
||||
});
|
||||
})
|
||||
.orUpdate(
|
||||
['updatedAt', 'value'],
|
||||
['userId', 'key', 'scope', 'domain'],
|
||||
{ upsertType: 'on-conflict-do-update' }
|
||||
)
|
||||
.execute();
|
||||
|
||||
if (domain == null) {
|
||||
// TODO: サードパーティアプリが傍受出来てしまうのでどうにかする
|
||||
|
|
Loading…
Add table
Reference in a new issue