export const cardsTable = sqliteTable('cards', {
id: text()
.primaryKey()
.default(sql`(lower(hex(randomblob(16))))`),
source: text().notNull(),
target: text().notNull(),
pronunciation: text().notNull(),
});
export const cardsRelations = relations(cardsTable, ({ many }) => ({
vocabulary: many(cardsToVocabularyTable),
}));
export const vocabularyTable = sqliteTable(
'vocabulary',
{
id: text()
.primaryKey()
.default(sql`(lower(hex(randomblob(16))))`),
source: text().notNull(),
target: text().notNull(),
pronunciation: text().notNull(),
},
(t) => [unique().on(t.source, t.target)]
);
export const vocabularyRelations = relations(vocabularyTable, ({ many }) => ({
cards: many(cardsToVocabularyTable),
}));
export const cardsToVocabularyTable = sqliteTable(
'cards_to_vocabulary',
{
cardId: text()
.notNull()
.references(() => cardsTable.id),
vocabularyId: text()
.notNull()
.references(() => vocabularyTable.id),
},
(t) => [primaryKey({ columns: [t.cardId, t.vocabularyId] })]
);
export const cardsToVocabularyRelations = relations(cardsToVocabularyTable, ({ one }) => ({
card: one(cardsTable, {
fields: [cardsToVocabularyTable.cardId],
references: [cardsTable.id],
}),
vocabulary: one(vocabularyTable, {
fields: [cardsToVocabularyTable.vocabularyId],
references: [vocabularyTable.id],
}),
}));
export const cardsTable = sqliteTable('cards', {
id: text()
.primaryKey()
.default(sql`(lower(hex(randomblob(16))))`),
source: text().notNull(),
target: text().notNull(),
pronunciation: text().notNull(),
});
export const cardsRelations = relations(cardsTable, ({ many }) => ({
vocabulary: many(cardsToVocabularyTable),
}));
export const vocabularyTable = sqliteTable(
'vocabulary',
{
id: text()
.primaryKey()
.default(sql`(lower(hex(randomblob(16))))`),
source: text().notNull(),
target: text().notNull(),
pronunciation: text().notNull(),
},
(t) => [unique().on(t.source, t.target)]
);
export const vocabularyRelations = relations(vocabularyTable, ({ many }) => ({
cards: many(cardsToVocabularyTable),
}));
export const cardsToVocabularyTable = sqliteTable(
'cards_to_vocabulary',
{
cardId: text()
.notNull()
.references(() => cardsTable.id),
vocabularyId: text()
.notNull()
.references(() => vocabularyTable.id),
},
(t) => [primaryKey({ columns: [t.cardId, t.vocabularyId] })]
);
export const cardsToVocabularyRelations = relations(cardsToVocabularyTable, ({ one }) => ({
card: one(cardsTable, {
fields: [cardsToVocabularyTable.cardId],
references: [cardsTable.id],
}),
vocabulary: one(vocabularyTable, {
fields: [cardsToVocabularyTable.vocabularyId],
references: [vocabularyTable.id],
}),
}));