Home / File/ mysqlSchema.ts — drizzle-orm Source File

mysqlSchema.ts — drizzle-orm Source File

Architecture documentation for mysqlSchema.ts, a typescript file in the drizzle-orm codebase. 2 imports, 1 dependents.

File typescript DrizzleORM SQLDialects 2 imports 1 dependents 2 functions

Entity Profile

Dependency Diagram

graph LR
  3f087bfc_8053_61d0_b1dc_ef6e6e757d9a["mysqlSchema.ts"]
  690f7dfc_0aea_9ee8_d6e7_26bbb3689031["drizzle-orm"]
  3f087bfc_8053_61d0_b1dc_ef6e6e757d9a --> 690f7dfc_0aea_9ee8_d6e7_26bbb3689031
  93ed9350_daa0_6c21_81a6_ed6b2a48bbdf["mysql-core"]
  3f087bfc_8053_61d0_b1dc_ef6e6e757d9a --> 93ed9350_daa0_6c21_81a6_ed6b2a48bbdf
  4f3cf996_699e_7aad_2f55_844994353684["cyclicTables.test.ts"]
  4f3cf996_699e_7aad_2f55_844994353684 --> 3f087bfc_8053_61d0_b1dc_ef6e6e757d9a
  style 3f087bfc_8053_61d0_b1dc_ef6e6e757d9a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { relations } from 'drizzle-orm';
import type { AnyMySqlColumn } from 'drizzle-orm/mysql-core';
import { int, mysqlTable, serial, text, varchar } from 'drizzle-orm/mysql-core';

// MODEL
export const modelTable = mysqlTable(
	'model',
	{
		id: serial().primaryKey(),
		name: varchar({ length: 256 }).notNull(),
		defaultImageId: int().references(() => modelImageTable.id),
	},
);

export const modelRelations = relations(modelTable, ({ one, many }) => ({
	images: many(modelImageTable),
	defaultImage: one(modelImageTable, {
		fields: [modelTable.defaultImageId],
		references: [modelImageTable.id],
	}),
}));

// MODEL IMAGE
export const modelImageTable = mysqlTable(
	'model_image',
	{
		id: serial().primaryKey(),
		url: varchar({ length: 256 }).notNull(),
		caption: varchar({ length: 256 }),
		modelId: int()
			.notNull()
			.references((): AnyMySqlColumn => modelTable.id),
	},
);

export const modelImageRelations = relations(modelImageTable, ({ one }) => ({
	model: one(modelTable, {
		fields: [modelImageTable.modelId],
		references: [modelTable.id],
	}),
}));

// 3 tables case
export const modelTable1 = mysqlTable(
	'model1',
	{
		id: serial().primaryKey(),
		name: varchar({ length: 256 }).notNull(),
		userId: int()
			.references(() => user.id),
		defaultImageId: int(),
	},
);

export const modelImageTable1 = mysqlTable(
	'model_image1',
	{
		id: serial().primaryKey(),
		url: varchar({ length: 256 }).notNull(),
		caption: varchar({ length: 256 }),
		modelId: int().notNull()
			.references((): AnyMySqlColumn => modelTable1.id),
	},
);

export const user = mysqlTable(
	'user',
	{
		id: serial().primaryKey(),
		name: text(),
		invitedBy: int().references((): AnyMySqlColumn => user.id),
		imageId: int()
			.notNull()
			.references((): AnyMySqlColumn => modelImageTable1.id),
	},
);

Domain

Subdomains

Dependencies

  • drizzle-orm
  • mysql-core

Frequently Asked Questions

What does mysqlSchema.ts do?
mysqlSchema.ts is a source file in the drizzle-orm codebase, written in typescript. It belongs to the DrizzleORM domain, SQLDialects subdomain.
What functions are defined in mysqlSchema.ts?
mysqlSchema.ts defines 2 function(s): modelImageRelations, modelRelations.
What does mysqlSchema.ts depend on?
mysqlSchema.ts imports 2 module(s): drizzle-orm, mysql-core.
What files import mysqlSchema.ts?
mysqlSchema.ts is imported by 1 file(s): cyclicTables.test.ts.
Where is mysqlSchema.ts in the architecture?
mysqlSchema.ts is located at drizzle-seed/tests/mysql/cyclicTables/mysqlSchema.ts (domain: DrizzleORM, subdomain: SQLDialects, directory: drizzle-seed/tests/mysql/cyclicTables).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free