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.
Entity Profile
Dependency Diagram
graph LR c6902f51_cbac_a2a7_c355_214086edee81["tables-rel.ts"] fa14e9c0_b73d_4bcb_463b_adf18df8a285["index.ts"] c6902f51_cbac_a2a7_c355_214086edee81 --> fa14e9c0_b73d_4bcb_463b_adf18df8a285 e4d6a0ab_9aa2_13a6_a2f1_58d94314c3f2["relations.ts"] c6902f51_cbac_a2a7_c355_214086edee81 --> e4d6a0ab_9aa2_13a6_a2f1_58d94314c3f2 8bd43940_8da9_ba3a_de4d_b6d7b7d1b9a7["db-rel.ts"] 8bd43940_8da9_ba3a_de4d_b6d7b7d1b9a7 --> c6902f51_cbac_a2a7_c355_214086edee81 style c6902f51_cbac_a2a7_c355_214086edee81 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import { foreignKey, integer, pgTable, serial, text, timestamp } from '~/pg-core/index.ts';
import { relations } from '~/relations.ts';
export const users = pgTable('users', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
cityId: integer('city_id').references(() => cities.id).notNull(),
homeCityId: integer('home_city_id').references(() => cities.id),
createdAt: timestamp('created_at', { withTimezone: true }).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 = pgTable('cities', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
});
export const citiesConfig = relations(cities, ({ many }) => ({
users: many(users, { relationName: 'UsersInCity' }),
}));
export const posts = pgTable('posts', {
id: serial('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 = pgTable('comments', {
id: serial('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 = pgTable('books', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
});
export const booksConfig = relations(books, ({ many }) => ({
authors: many(bookAuthors),
}));
export const bookAuthors = pgTable('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 = pgTable('node', {
id: serial('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
Functions
Dependencies
- index.ts
- relations.ts
Imported By
Source
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, DatabaseDrivers 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/pg/tables-rel.ts (domain: DrizzleORM, subdomain: DatabaseDrivers, directory: drizzle-orm/type-tests/pg).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free