本文整理汇总了TypeScript中objection.transaction.start方法的典型用法代码示例。如果您正苦于以下问题:TypeScript transaction.start方法的具体用法?TypeScript transaction.start怎么用?TypeScript transaction.start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类objection.transaction
的用法示例。
在下文中一共展示了transaction.start方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test("creates artist names", async () => {
expect.assertions(9);
const trx = await transaction.start(Artist.knex());
try {
let artist: Artist;
artist = await createArtistAndArtistNames(DEFAULT_PAYLOAD.input, trx);
artist = await artist.$loadRelated("names(orderById)", {
orderById: (builder) => builder.orderBy("id"),
}, trx);
const names = artist.names;
if (!names) { return; }
expect(names.length).toBe(2);
expect(names[0].is_default).toBe(false);
expect(names[0].is_original).toBe(true);
expect(names[0].locale).toBe("ko");
expect(names[0].name).toBe("루나");
expect(names[1].is_default).toBe(true);
expect(names[1].is_original).toBe(false);
expect(names[1].locale).toBe("ko-Latn");
expect(names[1].name).toBe("Luna");
} finally {
await trx.rollback();
}
});
示例2: test
test("updates an existing artist record", async () => {
expect.assertions(9);
const trx = await transaction.start(Artist.knex());
try {
let artist = await createArtist({}, trx);
artist = await artist.update({
country: "GB",
disambiguation: "group",
endedOn: PartialDate.parse("2017"),
kind: ArtistKind.Group,
}, trx);
expect(artist.country).toBe("GB");
expect(artist.disambiguation).toBe("group");
expect(artist.ended_on_year).toBe(2017);
expect(artist.ended_on_month).toBeNull();
expect(artist.ended_on_day).toBeNull();
expect(artist.kind).toBe(ArtistKind.Group);
expect(artist.started_on_year).toBe(1990);
expect(artist.started_on_month).toBe(8);
expect(artist.started_on_day).toBeNull();
} finally {
await trx.rollback();
}
});
示例3: test
test("#update", async () => {
expect.assertions(5);
const trx = await transaction.start(Artist.knex());
try {
const artist = await createArtist({}, trx);
let name = await createArtistName({ artistId: artist.id.toString() }, trx);
name = await name.update({
isDefault: false,
isOriginal: false,
locale: "ko-Latn",
name: "Exy",
}, trx);
expect(name.artist_id).toBe(artist.id);
expect(name.isDefault).toBe(false);
expect(name.isOriginal).toBe(false);
expect(name.locale).toBe("ko-Latn");
expect(name.name).toBe("Exy");
} finally {
await trx.rollback();
}
});