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 RelationalQuery 5 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  a46dd24f_ee58_677a_929f_cb428efb71ba["db-rel.ts"]
  c97e2b55_026c_83f4_2bf3_25f61840b9cd["tables-rel.ts"]
  a46dd24f_ee58_677a_929f_cb428efb71ba --> c97e2b55_026c_83f4_2bf3_25f61840b9cd
  90067f6e_33cd_67c4_3575_3758cdacb6e2["gel"]
  a46dd24f_ee58_677a_929f_cb428efb71ba --> 90067f6e_33cd_67c4_3575_3758cdacb6e2
  25b05299_f48f_bceb_01ca_1343d330a8f7["utils.ts"]
  a46dd24f_ee58_677a_929f_cb428efb71ba --> 25b05299_f48f_bceb_01ca_1343d330a8f7
  3c14ba92_db3c_ef9d_1680_03a30f6bbd12["index.ts"]
  a46dd24f_ee58_677a_929f_cb428efb71ba --> 3c14ba92_db3c_ef9d_1680_03a30f6bbd12
  be483a7f_d5d7_7a9b_9a13_44a4a6aafbbd["sql.ts"]
  a46dd24f_ee58_677a_929f_cb428efb71ba --> be483a7f_d5d7_7a9b_9a13_44a4a6aafbbd
  style a46dd24f_ee58_677a_929f_cb428efb71ba fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

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

const db = drizzle(gel.createClient(), { schema });

{
	const result = await db.query.users.findMany({
		where: (users, { sql }) => sql`char_length(${users.name} > 1)`,
		limit: sql.placeholder('l'),
		orderBy: (users, { asc, desc }) => [asc(users.name), desc(users.id)],
		with: {
			posts: {
				where: (posts, { sql }) => sql`char_length(${posts.title} > 1)`,
				limit: sql.placeholder('l'),
				columns: {
					id: false,
					title: undefined,
				},
				with: {
					author: true,
					comments: {
						where: (comments, { sql }) => sql`char_length(${comments.text} > 1)`,
						limit: sql.placeholder('l'),
						columns: {
							text: true,
						},
						with: {
							author: {
								columns: {
									id: undefined,
								},
								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, RelationalQuery 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): gel, index.ts, 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/geldb/db-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