Represent a table that contains an variants with strict keys (aka `Record` mapped type)?

I have a table that represents words (it's an English learning platform) where each word should have two examples (eg US and UK). How to display such a connection? This is not a repeater field where we can create many records attached to a word, but rather an already defined dataset with (in our case) two keys.
export const word = sqliteTable('word', {
id: integer('id').notNull().primaryKey(),
name: text('name', { mode: 'text', length: 255 }).notNull().unique(),

// ?
// examples: text('examples', { mode: 'json' }).$type<Record<'us' | 'uk', { value: string }>>().notNull(),
// ?
// examples: text('examples', { mode: 'json' }).$type<Array<{ value: string }>>().notNull(),
});

// ?
export const wordExample = sqliteTable('word_example', {
id: integer('id').notNull().primaryKey(),
wordId: integer('word_id').references(() => word.id, { onDelete: 'cascade' }).unique(),
type: text('type', { enum: ['us', 'uk'] }).notNull().unique(),
value: text('value', { mode: 'text' }).notNull(),
});
export const word = sqliteTable('word', {
id: integer('id').notNull().primaryKey(),
name: text('name', { mode: 'text', length: 255 }).notNull().unique(),

// ?
// examples: text('examples', { mode: 'json' }).$type<Record<'us' | 'uk', { value: string }>>().notNull(),
// ?
// examples: text('examples', { mode: 'json' }).$type<Array<{ value: string }>>().notNull(),
});

// ?
export const wordExample = sqliteTable('word_example', {
id: integer('id').notNull().primaryKey(),
wordId: integer('word_id').references(() => word.id, { onDelete: 'cascade' }).unique(),
type: text('type', { enum: ['us', 'uk'] }).notNull().unique(),
value: text('value', { mode: 'text' }).notNull(),
});
1 Reply
predaytor
predaytorOP6mo ago
up
Want results from more Discord servers?
Add your server