Home / File/ tables-rel.ts — drizzle-orm Source File

tables-rel.ts — drizzle-orm Source File

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

File typescript DrizzleORM RelationalQuery 2 imports 1 dependents 8 functions

Entity Profile

Dependency Diagram

graph LR
  c97e2b55_026c_83f4_2bf3_25f61840b9cd["tables-rel.ts"]
  076448f5_e30d_7700_bbe9_f5d1e76b579a["index.ts"]
  c97e2b55_026c_83f4_2bf3_25f61840b9cd --> 076448f5_e30d_7700_bbe9_f5d1e76b579a
  e4d6a0ab_9aa2_13a6_a2f1_58d94314c3f2["relations.ts"]
  c97e2b55_026c_83f4_2bf3_25f61840b9cd --> e4d6a0ab_9aa2_13a6_a2f1_58d94314c3f2
  a46dd24f_ee58_677a_929f_cb428efb71ba["db-rel.ts"]
  a46dd24f_ee58_677a_929f_cb428efb71ba --> c97e2b55_026c_83f4_2bf3_25f61840b9cd
  style c97e2b55_026c_83f4_2bf3_25f61840b9cd fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { foreignKey, gelTable, integer, text, timestamptz } from '~/gel-core/index.ts';
import { relations } from '~/relations.ts';

export const users = gelTable('users', {
	id: integer('id').primaryKey(),
	name: text('name').notNull(),
	cityId: integer('city_id').references(() => cities.id).notNull(),
	homeCityId: integer('home_city_id').references(() => cities.id),
	createdAt: timestamptz('created_at').notNull(),
});
export const usersConfig = relations(users, ({ one, many }) => ({
	city: one(cities, { relationName: 'UsersInCity', fields: [users.cityId], references: [cities.id] }),
	homeCity: one(cities, { fields: [users.homeCityId], references: [cities.id] }),
	posts: many(posts),
	comments: many(comments),
}));

export const cities = gelTable('cities', {
	id: integer('id').primaryKey(),
	name: text('name').notNull(),
});
export const citiesConfig = relations(cities, ({ many }) => ({
	users: many(users, { relationName: 'UsersInCity' }),
}));

export const posts = gelTable('posts', {
	id: integer('id').primaryKey(),
	title: text('title').notNull(),
	authorId: integer('author_id').references(() => users.id),
});
export const postsConfig = relations(posts, ({ one, many }) => ({
	author: one(users, { fields: [posts.authorId], references: [users.id] }),
	comments: many(comments),
}));

export const comments = gelTable('comments', {
	id: integer('id').primaryKey(),
	postId: integer('post_id').references(() => posts.id).notNull(),
	authorId: integer('author_id').references(() => users.id),
	text: text('text').notNull(),
});
export const commentsConfig = relations(comments, ({ one }) => ({
	post: one(posts, { fields: [comments.postId], references: [posts.id] }),
	author: one(users, { fields: [comments.authorId], references: [users.id] }),
}));

export const books = gelTable('books', {
	id: integer('id').primaryKey(),
	name: text('name').notNull(),
});
export const booksConfig = relations(books, ({ many }) => ({
	authors: many(bookAuthors),
}));

export const bookAuthors = gelTable('book_authors', {
	bookId: integer('book_id').references(() => books.id).notNull(),
	authorId: integer('author_id').references(() => users.id).notNull(),
	role: text('role').notNull(),
});
export const bookAuthorsConfig = relations(bookAuthors, ({ one }) => ({
	book: one(books, { fields: [bookAuthors.bookId], references: [books.id] }),
	author: one(users, { fields: [bookAuthors.authorId], references: [users.id] }),
}));

export const node = gelTable('node', {
	id: integer('id').primaryKey(),
	parentId: integer('parent_id'),
	leftId: integer('left_id'),
	rightId: integer('right_id'),
}, (node) => ({
	fk1: foreignKey({ columns: [node.parentId], foreignColumns: [node.id] }),
	fk2: foreignKey({ columns: [node.leftId], foreignColumns: [node.id] }),
	fk3: foreignKey({ columns: [node.rightId], foreignColumns: [node.id] }),
}));
export const nodeRelations = relations(node, ({ one }) => ({
	parent: one(node, { fields: [node.parentId], references: [node.id] }),
	left: one(node, { fields: [node.leftId], references: [node.id] }),
	right: one(node, { fields: [node.rightId], references: [node.id] }),
}));

Domain

Subdomains

Dependencies

  • index.ts
  • relations.ts

Frequently Asked Questions

What does tables-rel.ts do?
tables-rel.ts is a source file in the drizzle-orm codebase, written in typescript. It belongs to the DrizzleORM domain, RelationalQuery subdomain.
What functions are defined in tables-rel.ts?
tables-rel.ts defines 8 function(s): bookAuthorsConfig, booksConfig, citiesConfig, commentsConfig, node, nodeRelations, postsConfig, usersConfig.
What does tables-rel.ts depend on?
tables-rel.ts imports 2 module(s): index.ts, relations.ts.
What files import tables-rel.ts?
tables-rel.ts is imported by 1 file(s): db-rel.ts.
Where is tables-rel.ts in the architecture?
tables-rel.ts is located at drizzle-orm/type-tests/geldb/tables-rel.ts (domain: DrizzleORM, subdomain: RelationalQuery, directory: drizzle-orm/type-tests/geldb).

Analyze Your Own Codebase

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

Try Supermodel Free