export const tokensTable = mysqlTable(
'tokens',
{
tokenId: varchar('token_id', { length: 255 }).notNull(),
metadataName: varchar('metadata_name', { length: 255 }),
metadataDescription: text('metadata_description'),
collectionId: varbinary('collection_id', {
length: 42,
}).notNull(),
createdAt: timestamp('created_at', {
mode: 'string',
}).defaultNow(),
updatedAt: timestamp('updated_at', {
mode: 'string',
}).defaultNow(),
}
)
export type Token = InferSelectModel<typeof tokensTable>
export type TokenInsert = InferInsertModel<typeof tokensTable>
export const tokensRelations = relations(tokensTable, ({ one }) => ({
collection: one(collectionsTable, {
fields: [tokensTable.collectionId],
references: [collectionsTable.id],
}),
}))
export const collectionsTable = mysqlTable(
'collections',
{
id: varbinary('id', {
length: 42,
}).primaryKey(),
name: varchar('name', {
length: 255,
}).notNull(),
description: text('description'),
createdAt: timestamp('created_at', {
mode: 'string',
}).defaultNow(),
updatedAt: timestamp('updated_at', {
mode: 'string',
}).defaultNow(),
}
)
export type Collection = InferSelectModel<typeof collectionsTable>
export type CollectionInsert = InferInsertModel<typeof collectionsTable>
export const collectionsRelations = relations(collectionsTable, ({ one, many }) => ({
tokens: many(tokensTable, {
relationName: 'collectionTokens',
}),
}))
export const tokensTable = mysqlTable(
'tokens',
{
tokenId: varchar('token_id', { length: 255 }).notNull(),
metadataName: varchar('metadata_name', { length: 255 }),
metadataDescription: text('metadata_description'),
collectionId: varbinary('collection_id', {
length: 42,
}).notNull(),
createdAt: timestamp('created_at', {
mode: 'string',
}).defaultNow(),
updatedAt: timestamp('updated_at', {
mode: 'string',
}).defaultNow(),
}
)
export type Token = InferSelectModel<typeof tokensTable>
export type TokenInsert = InferInsertModel<typeof tokensTable>
export const tokensRelations = relations(tokensTable, ({ one }) => ({
collection: one(collectionsTable, {
fields: [tokensTable.collectionId],
references: [collectionsTable.id],
}),
}))
export const collectionsTable = mysqlTable(
'collections',
{
id: varbinary('id', {
length: 42,
}).primaryKey(),
name: varchar('name', {
length: 255,
}).notNull(),
description: text('description'),
createdAt: timestamp('created_at', {
mode: 'string',
}).defaultNow(),
updatedAt: timestamp('updated_at', {
mode: 'string',
}).defaultNow(),
}
)
export type Collection = InferSelectModel<typeof collectionsTable>
export type CollectionInsert = InferInsertModel<typeof collectionsTable>
export const collectionsRelations = relations(collectionsTable, ({ one, many }) => ({
tokens: many(tokensTable, {
relationName: 'collectionTokens',
}),
}))