MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / insertTestData

Function insertTestData

tests/features/mikro-kysely-plugin.test.ts:433–511  ·  view source on GitHub ↗
(kysely: Kysely<DB>)

Source from the content-addressed store, hash-verified

431 });
432
433 const insertTestData = async (kysely: Kysely<DB>) => {
434 // Insert test data: Person -> Pet -> Toy
435 const now = new Date();
436 const person1Id = await kysely
437 .insertInto('person')
438 .values({
439 firstName: 'John',
440 lastName: 'Doe',
441 gender: 'male',
442 children: 0,
443 createdAt: now,
444 updatedAt: now,
445 })
446 .returning('id')
447 .executeTakeFirstOrThrow()
448 .then(r => r.id);
449
450 const person2Id = await kysely
451 .insertInto('person')
452 .values({
453 firstName: 'Jane',
454 lastName: 'Smith',
455 gender: 'female',
456 children: 2,
457 createdAt: now,
458 updatedAt: now,
459 })
460 .returning('id')
461 .executeTakeFirstOrThrow()
462 .then(r => r.id);
463
464 const pet1Id = await kysely
465 .insertInto('pet')
466 .values({
467 name: 'Buddy',
468 owner: person1Id,
469 species: 'dog',
470 createdAt: now,
471 updatedAt: now,
472 })
473 .returning('id')
474 .executeTakeFirstOrThrow()
475 .then(r => r.id);
476
477 const pet2Id = await kysely
478 .insertInto('pet')
479 .values({
480 name: 'Fluffy',
481 owner: person2Id,
482 species: 'cat',
483 createdAt: now,
484 updatedAt: now,
485 })
486 .returning('id')
487 .executeTakeFirstOrThrow()
488 .then(r => r.id);
489
490 await kysely

Callers 1

Calls 3

returningMethod · 0.65
executeMethod · 0.65
valuesMethod · 0.45

Tested by

no test coverage detected