本文整理匯總了TypeScript中objection.transaction類的典型用法代碼示例。如果您正苦於以下問題:TypeScript transaction類的具體用法?TypeScript transaction怎麽用?TypeScript transaction使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了transaction類的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();
}
});