MCPcopy
hub / github.com/kysely-org/kysely / initJSONTest

Function initJSONTest

test/node/src/test-setup.ts:603–653  ·  view source on GitHub ↗
(
  ctx: Mocha.Context,
  dialect: D,
)

Source from the content-addressed store, hash-verified

601export type JSONTestContext = Awaited<ReturnType<typeof initJSONTest>>
602
603export async function initJSONTest<D extends DialectDescriptor>(
604 ctx: Mocha.Context,
605 dialect: D,
606) {
607 const testContext = await initTest(ctx, dialect)
608
609 let db = testContext.db.withTables<{
610 person_metadata: {
611 person_id: number
612 website: JSONColumnType<{ url: string }>
613 nicknames: JSONColumnType<string[]>
614 profile: JSONColumnType<{
615 auth: {
616 roles: string[]
617 last_login?: { device: string }
618 is_verified: SqlBool
619 login_count: number
620 }
621 avatar: string | null
622 tags: string[]
623 }>
624 experience: JSONColumnType<
625 {
626 establishment: string
627 }[]
628 >
629 schedule: JSONColumnType<{ name: string; time: string }[][][]>
630 }
631 }>()
632
633 if (dialect.sqlSpec === 'sqlite') {
634 db = db.withPlugin(new ParseJSONResultsPlugin())
635 }
636
637 const jsonColumnDataType = resolveJSONColumnDataType(dialect)
638 const notNull = (cb: ColumnDefinitionBuilder) => cb.notNull()
639
640 await db.schema
641 .createTable('person_metadata')
642 .addColumn('person_id', 'integer', (cb) =>
643 cb.primaryKey().references('person.id'),
644 )
645 .addColumn('website', jsonColumnDataType, notNull)
646 .addColumn('nicknames', jsonColumnDataType, notNull)
647 .addColumn('profile', jsonColumnDataType, notNull)
648 .addColumn('experience', jsonColumnDataType, notNull)
649 .addColumn('schedule', jsonColumnDataType, notNull)
650 .execute()
651
652 return { ...testContext, db }
653}
654
655export function resolveJSONColumnDataType(
656 dialect: DialectDescriptor,

Callers 2

Calls 9

initTestFunction · 0.85
createTableMethod · 0.80
referencesMethod · 0.80
primaryKeyMethod · 0.80
withTablesMethod · 0.65
withPluginMethod · 0.65
executeMethod · 0.65
addColumnMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…