Compare commits
1 commit
develop
...
use-insert
Author | SHA1 | Date | |
---|---|---|---|
|
6d22032b61 |
7 changed files with 23 additions and 23 deletions
|
@ -18,9 +18,9 @@ export async function fetchMeta(noCache = false): Promise<Meta> {
|
|||
cache = meta;
|
||||
return meta;
|
||||
} else {
|
||||
const saved = await transactionalEntityManager.save(Meta, {
|
||||
const saved = await transactionalEntityManager.insert(Meta, {
|
||||
id: 'x'
|
||||
}) as Meta;
|
||||
}).then(x => transactionalEntityManager.findOneOrFail(Meta, x.identifiers[0]));
|
||||
|
||||
cache = saved;
|
||||
return saved;
|
||||
|
|
|
@ -145,7 +145,7 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
|
|||
try {
|
||||
// Start transaction
|
||||
await getConnection().transaction(async transactionalEntityManager => {
|
||||
user = await transactionalEntityManager.save(new User({
|
||||
user = await transactionalEntityManager.insert(User, {
|
||||
id: genId(),
|
||||
avatarId: null,
|
||||
bannerId: null,
|
||||
|
@ -163,9 +163,9 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
|
|||
tags,
|
||||
isBot,
|
||||
isCat: (person as any).isCat === true
|
||||
})) as IRemoteUser;
|
||||
}).then(x => transactionalEntityManager.findOneOrFail(User, x.identifiers[0])) as IRemoteUser;
|
||||
|
||||
await transactionalEntityManager.save(new UserProfile({
|
||||
await transactionalEntityManager.insert(UserProfile, {
|
||||
userId: user.id,
|
||||
description: person.summary ? htmlToMfm(person.summary, person.tag) : null,
|
||||
url: getOneApHrefNullable(person.url),
|
||||
|
@ -173,13 +173,13 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
|
|||
birthday: bday ? bday[0] : null,
|
||||
location: person['vcard:Address'] || null,
|
||||
userHost: host
|
||||
}));
|
||||
});
|
||||
|
||||
await transactionalEntityManager.save(new UserPublickey({
|
||||
await transactionalEntityManager.insert(UserPublickey, {
|
||||
userId: user.id,
|
||||
keyId: person.publicKey.id,
|
||||
keyPem: person.publicKey.publicKeyPem
|
||||
}));
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
// duplicate key error
|
||||
|
|
|
@ -67,7 +67,7 @@ export async function signup(username: User['username'], password: UserProfile['
|
|||
|
||||
if (exist) throw new Error(' the username is already used');
|
||||
|
||||
account = await transactionalEntityManager.save(new User({
|
||||
account = await transactionalEntityManager.insert(User,{
|
||||
id: genId(),
|
||||
createdAt: new Date(),
|
||||
username: username,
|
||||
|
@ -77,24 +77,24 @@ export async function signup(username: User['username'], password: UserProfile['
|
|||
isAdmin: (await Users.count({
|
||||
host: null,
|
||||
})) === 0,
|
||||
}));
|
||||
}).then(x => transactionalEntityManager.findOneOrFail(User, x.identifiers[0]));
|
||||
|
||||
await transactionalEntityManager.save(new UserKeypair({
|
||||
await transactionalEntityManager.insert(UserKeypair, {
|
||||
publicKey: keyPair[0],
|
||||
privateKey: keyPair[1],
|
||||
userId: account.id
|
||||
}));
|
||||
});
|
||||
|
||||
await transactionalEntityManager.save(new UserProfile({
|
||||
await transactionalEntityManager.insert(UserProfile, {
|
||||
userId: account.id,
|
||||
autoAcceptFollowed: true,
|
||||
password: hash,
|
||||
}));
|
||||
});
|
||||
|
||||
await transactionalEntityManager.save(new UsedUsername({
|
||||
await transactionalEntityManager.insert(UsedUsername, {
|
||||
createdAt: new Date(),
|
||||
username: username.toLowerCase(),
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
usersChart.update(account, true);
|
||||
|
|
|
@ -691,7 +691,7 @@ export default define(meta, async (ps, me) => {
|
|||
if (meta) {
|
||||
await transactionalEntityManager.update(Meta, meta.id, set);
|
||||
} else {
|
||||
await transactionalEntityManager.save(Meta, set);
|
||||
await transactionalEntityManager.insert(Meta, set);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -55,14 +55,14 @@ export default define(meta, async (ps, user) => {
|
|||
}
|
||||
}
|
||||
|
||||
const channel = await Channels.save({
|
||||
const channel = await Channels.insert({
|
||||
id: genId(),
|
||||
createdAt: new Date(),
|
||||
userId: user.id,
|
||||
name: ps.name,
|
||||
description: ps.description || null,
|
||||
bannerId: banner ? banner.id : null,
|
||||
} as Channel);
|
||||
}).then(x => Channels.findOneOrFail(x.identifiers[0]));
|
||||
|
||||
return await Channels.pack(channel, user);
|
||||
});
|
||||
|
|
|
@ -305,12 +305,12 @@ export default abstract class Chart<T extends Record<string, any>> {
|
|||
if (currentLog != null) return currentLog;
|
||||
|
||||
// 新規ログ挿入
|
||||
log = await this.repository.save({
|
||||
log = await this.repository.insert({
|
||||
group: group,
|
||||
span: span,
|
||||
date: date,
|
||||
...Chart.convertObjectToFlattenColumns(data)
|
||||
});
|
||||
}).then(x => this.repository.findOneOrFail(x.identifiers[0]));
|
||||
|
||||
logger.info(`${this.name + (group ? `:${group}` : '')} (${span}): New commit created`);
|
||||
|
||||
|
|
|
@ -33,13 +33,13 @@ export default async (user: User, note: Note, reaction?: string) => {
|
|||
}
|
||||
|
||||
// Create reaction
|
||||
const inserted = await NoteReactions.save({
|
||||
const inserted = await NoteReactions.insert({
|
||||
id: genId(),
|
||||
createdAt: new Date(),
|
||||
noteId: note.id,
|
||||
userId: user.id,
|
||||
reaction
|
||||
});
|
||||
}).then(x => NoteReactions.findOneOrFail(x.identifiers[0]));
|
||||
|
||||
// Increment reactions count
|
||||
const sql = `jsonb_set("reactions", '{${reaction}}', (COALESCE("reactions"->>'${reaction}', '0')::int + 1)::text::jsonb)`;
|
||||
|
|
Loading…
Reference in a new issue