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