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

db-rel.ts — drizzle-orm Source File

Architecture documentation for db-rel.ts, a typescript file in the drizzle-orm codebase. 5 imports, 0 dependents.

File typescript DrizzleORM SQLDialects 5 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  4f7f92d5_10ea_2e64_4624_0fd0e1943bc0["db-rel.ts"]
  b1dda328_eebf_52f2_97d5_00501c61feeb["tables-rel.ts"]
  4f7f92d5_10ea_2e64_4624_0fd0e1943bc0 --> b1dda328_eebf_52f2_97d5_00501c61feeb
  0d277acf_0d68_9daf_8724_642232a89719["pg"]
  4f7f92d5_10ea_2e64_4624_0fd0e1943bc0 --> 0d277acf_0d68_9daf_8724_642232a89719
  25b05299_f48f_bceb_01ca_1343d330a8f7["utils.ts"]
  4f7f92d5_10ea_2e64_4624_0fd0e1943bc0 --> 25b05299_f48f_bceb_01ca_1343d330a8f7
  b5ed0e87_40a4_1643_f027_4ff3496c71c0["index.ts"]
  4f7f92d5_10ea_2e64_4624_0fd0e1943bc0 --> b5ed0e87_40a4_1643_f027_4ff3496c71c0
  be483a7f_d5d7_7a9b_9a13_44a4a6aafbbd["sql.ts"]
  4f7f92d5_10ea_2e64_4624_0fd0e1943bc0 --> be483a7f_d5d7_7a9b_9a13_44a4a6aafbbd
  style 4f7f92d5_10ea_2e64_4624_0fd0e1943bc0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import pg from 'pg';
import { type Equal, Expect } from 'type-tests/utils.ts';
import { drizzle } from '~/node-postgres/index.ts';
import { placeholder, sql } from '~/sql/sql.ts';
import * as schema from './tables-rel.ts';

const { Pool } = pg;

const pdb = new Pool({ connectionString: process.env['PG_CONNECTION_STRING'] });
const db = drizzle(pdb, { schema });

{
	const result = await db.query.users.findMany({
		where: (users, { sql }) => sql`char_length(${users.name} > 1)`,
		limit: placeholder('l'),
		orderBy: (users, { asc, desc }) => [asc(users.name), desc(users.id)],
		with: {
			posts: {
				where: (posts, { sql }) => sql`char_length(${posts.title} > 1)`,
				limit: placeholder('l'),
				columns: {
					id: false,
				},
				with: {
					author: true,
					comments: {
						where: (comments, { sql }) => sql`char_length(${comments.text} > 1)`,
						limit: placeholder('l'),
						columns: {
							text: true,
						},
						with: {
							author: {
								columns: {},
								with: {
									city: {
										with: {
											users: true,
										},
									},
								},
							},
						},
					},
				},
			},
		},
	});

	Expect<
		Equal<{
			id: number;
			name: string;
			cityId: number;
			homeCityId: number | null;
			createdAt: Date;
			posts: {
				title: string;
				authorId: number | null;
				comments: {
					text: string;
					author: {
						city: {
							id: number;
							name: string;
							users: {
								id: number;
								name: string;
								cityId: number;
								homeCityId: number | null;
								createdAt: Date;
							}[];
						};
					} | null;
				}[];
				author: {
					id: number;
					name: string;
					cityId: number;
					homeCityId: number | null;
					createdAt: Date;
				} | null;
			}[];
		}[], typeof result>
	>;
}

{
	const result = await db.query.users.findMany({
		columns: {
			id: true,
			name: true,
		},
		with: {
			posts: {
				columns: {
					authorId: true,
				},
				extras: {
					lower: sql<string>`lower(${schema.posts.title})`.as('lower_name'),
				},
			},
		},
	});

	Expect<
		Equal<
			{
				id: number;
				name: string;
				posts: {
					authorId: number | null;
					lower: string;
				}[];
			}[],
			typeof result
		>
	>;
}

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does db-rel.ts do?
db-rel.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 db-rel.ts?
db-rel.ts defines 2 function(s): result.orderBy, result.where.
What does db-rel.ts depend on?
db-rel.ts imports 5 module(s): index.ts, pg, sql.ts, tables-rel.ts, utils.ts.
Where is db-rel.ts in the architecture?
db-rel.ts is located at drizzle-orm/type-tests/mysql/db-rel.ts (domain: DrizzleORM, subdomain: SQLDialects, directory: drizzle-orm/type-tests/mysql).

Analyze Your Own Codebase

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

Try Supermodel Free