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

sqliteSchema.ts — drizzle-orm Source File

Architecture documentation for sqliteSchema.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
  5659173e_10c3_b510_370d_a56f6270379e["sqliteSchema.ts"]
  690f7dfc_0aea_9ee8_d6e7_26bbb3689031["drizzle-orm"]
  5659173e_10c3_b510_370d_a56f6270379e --> 690f7dfc_0aea_9ee8_d6e7_26bbb3689031
  25248a9d_ba06_2b33_4421_8575da2f9c34["sqlite-core"]
  5659173e_10c3_b510_370d_a56f6270379e --> 25248a9d_ba06_2b33_4421_8575da2f9c34
  58508db8_cac1_489b_4e83_d8e0aa938b6d["cyclicTables.test.ts"]
  58508db8_cac1_489b_4e83_d8e0aa938b6d --> 5659173e_10c3_b510_370d_a56f6270379e
  style 5659173e_10c3_b510_370d_a56f6270379e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { relations } from 'drizzle-orm';
import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';
import type { AnySQLiteColumn } from 'drizzle-orm/sqlite-core';

// MODEL
export const modelTable = sqliteTable(
	'model',
	{
		id: integer().primaryKey(),
		name: text().notNull(),
		defaultImageId: integer().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 = sqliteTable(
	'model_image',
	{
		id: integer().primaryKey(),
		url: text().notNull(),
		caption: text(),
		modelId: integer()
			.notNull()
			.references((): AnySQLiteColumn => modelTable.id),
	},
);

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

// 3 tables case
export const modelTable1 = sqliteTable(
	'model1',
	{
		id: integer().primaryKey(),
		name: text().notNull(),
		userId: integer()
			.references(() => user.id),
		defaultImageId: integer().references(() => modelImageTable1.id),
	},
);

export const modelImageTable1 = sqliteTable(
	'model_image1',
	{
		id: integer().primaryKey(),
		url: text().notNull(),
		caption: text(),
		modelId: integer().notNull()
			.references((): AnySQLiteColumn => modelTable1.id),
	},
);

export const user = sqliteTable(
	'user',
	{
		id: integer().primaryKey(),
		name: text(),
		invitedBy: integer().references((): AnySQLiteColumn => user.id),
		imageId: integer()
			.notNull()
			.references((): AnySQLiteColumn => modelImageTable1.id),
	},
);

Domain

Subdomains

Dependencies

  • drizzle-orm
  • sqlite-core

Frequently Asked Questions

What does sqliteSchema.ts do?
sqliteSchema.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 sqliteSchema.ts?
sqliteSchema.ts defines 2 function(s): modelImageRelations, modelRelations.
What does sqliteSchema.ts depend on?
sqliteSchema.ts imports 2 module(s): drizzle-orm, sqlite-core.
What files import sqliteSchema.ts?
sqliteSchema.ts is imported by 1 file(s): cyclicTables.test.ts.
Where is sqliteSchema.ts in the architecture?
sqliteSchema.ts is located at drizzle-seed/tests/sqlite/cyclicTables/sqliteSchema.ts (domain: DrizzleORM, subdomain: SQLDialects, directory: drizzle-seed/tests/sqlite/cyclicTables).

Analyze Your Own Codebase

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

Try Supermodel Free