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

subquery.ts — drizzle-orm Source File

Architecture documentation for subquery.ts, a typescript file in the drizzle-orm codebase. 7 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  a67a26f6_284d_3bb4_0563_5b97b29f0484["subquery.ts"]
  0e3c50de_fbb6_eb17_22a4_8121934f6fdf["db.ts"]
  a67a26f6_284d_3bb4_0563_5b97b29f0484 --> 0e3c50de_fbb6_eb17_22a4_8121934f6fdf
  25b05299_f48f_bceb_01ca_1343d330a8f7["utils.ts"]
  a67a26f6_284d_3bb4_0563_5b97b29f0484 --> 25b05299_f48f_bceb_01ca_1343d330a8f7
  1da0a48e_f7fe_5ea4_cee2_3ed7d3f39f31["index.ts"]
  a67a26f6_284d_3bb4_0563_5b97b29f0484 --> 1da0a48e_f7fe_5ea4_cee2_3ed7d3f39f31
  5c46beaf_8b59_d2e3_def3_8af6daf1fccd["index.ts"]
  a67a26f6_284d_3bb4_0563_5b97b29f0484 --> 5c46beaf_8b59_d2e3_def3_8af6daf1fccd
  dd168f9e_7bec_1d6c_c69f_0fed98c81f3c["aggregate.ts"]
  a67a26f6_284d_3bb4_0563_5b97b29f0484 --> dd168f9e_7bec_1d6c_c69f_0fed98c81f3c
  be483a7f_d5d7_7a9b_9a13_44a4a6aafbbd["sql.ts"]
  a67a26f6_284d_3bb4_0563_5b97b29f0484 --> be483a7f_d5d7_7a9b_9a13_44a4a6aafbbd
  ecce3253_1e75_a87f_27b3_ca87e81a3024["utils.ts"]
  a67a26f6_284d_3bb4_0563_5b97b29f0484 --> ecce3253_1e75_a87f_27b3_ca87e81a3024
  style a67a26f6_284d_3bb4_0563_5b97b29f0484 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { Expect } from 'type-tests/utils.ts';
import { alias, int, mysqlTable, serial, text } from '~/mysql-core/index.ts';
import { and, eq } from '~/sql/expressions/index.ts';
import { count } from '~/sql/functions/aggregate.ts';
import { sql } from '~/sql/sql.ts';
import type { DrizzleTypeError, Equal } from '~/utils.ts';
import { db } from './db.ts';

const users = mysqlTable('names', {
	id: serial('id').primaryKey(),
	name: text('name'),
	managerId: int('author_id'),
});

const posts = mysqlTable('posts', {
	id: serial('id').primaryKey(),
	authorId: int('author_id'),
	title: text('title'),
});

const n1 = db
	.select({
		id: users.id,
		name: users.name,
		authorId: users.managerId,
		count1: sql<number>`count(1)::int`.as('count1'),
	})
	.from(users)
	.groupBy(users.id, users.name, users.managerId)
	.as('n1');

const n2 = db
	.select({
		id: users.id,
		authorId: users.managerId,
		totalCount: sql<number>`count(1)::int`.as('totalCount'),
	})
	.from(users)
	.groupBy(users.id, users.managerId)
	.as('n2');

const result = await db
	.select({
		name: n1.name,
		authorId: n1.authorId,
		count1: n1.count1,
		totalCount: n2.totalCount,
	})
	.from(n1)
	.innerJoin(n2, and(eq(n2.id, n1.id), eq(n2.authorId, n1.authorId)));

Expect<
	Equal<
		{
			name: string | null;
			authorId: number | null;
			count1: number;
			totalCount: number;
		}[],
		typeof result
// ... (65 more lines)

Domain

Dependencies

  • aggregate.ts
  • db.ts
  • index.ts
  • index.ts
  • sql.ts
  • utils.ts
  • utils.ts

Frequently Asked Questions

What does subquery.ts do?
subquery.ts is a source file in the drizzle-orm codebase, written in typescript. It belongs to the DrizzleORM domain.
What does subquery.ts depend on?
subquery.ts imports 7 module(s): aggregate.ts, db.ts, index.ts, index.ts, sql.ts, utils.ts, utils.ts.
Where is subquery.ts in the architecture?
subquery.ts is located at drizzle-orm/type-tests/mysql/subquery.ts (domain: DrizzleORM, 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