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,18 +27,23 @@ export class RegistryApiService {
|
||||||
public async set(userId: MiUser['id'], domain: string | null, scope: string[], key: string, value: any) {
|
public async set(userId: MiUser['id'], domain: string | null, scope: string[], key: string, value: any) {
|
||||||
// TODO: 作成できるキーの数を制限する
|
// TODO: 作成できるキーの数を制限する
|
||||||
|
|
||||||
await this.registryItemsRepository.upsert({
|
await this.registryItemsRepository.createQueryBuilder('item')
|
||||||
id: this.idService.gen(),
|
.insert()
|
||||||
updatedAt: new Date(),
|
.values({
|
||||||
userId: userId,
|
id: this.idService.gen(),
|
||||||
domain: domain,
|
updatedAt: new Date(),
|
||||||
scope: scope,
|
userId: userId,
|
||||||
key: key,
|
domain: domain,
|
||||||
value: value,
|
scope: scope,
|
||||||
}, {
|
key: key,
|
||||||
conflictPaths: ['userId', 'key', 'scope', 'domain'],
|
value: value,
|
||||||
upsertType: 'on-conflict-do-update',
|
})
|
||||||
});
|
.orUpdate(
|
||||||
|
['updatedAt', 'value'],
|
||||||
|
['userId', 'key', 'scope', 'domain'],
|
||||||
|
{ upsertType: 'on-conflict-do-update' }
|
||||||
|
)
|
||||||
|
.execute();
|
||||||
|
|
||||||
if (domain == null) {
|
if (domain == null) {
|
||||||
// TODO: サードパーティアプリが傍受出来てしまうのでどうにかする
|
// TODO: サードパーティアプリが傍受出来てしまうのでどうにかする
|
||||||
|
|
Loading…
Add table
Reference in a new issue