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
  37bb944f_c341_9402_552c_323dacda08be["subquery.ts"]
  9a56da77_7540_380c_f8b9_d8bde4914940["db.ts"]
  37bb944f_c341_9402_552c_323dacda08be --> 9a56da77_7540_380c_f8b9_d8bde4914940
  25b05299_f48f_bceb_01ca_1343d330a8f7["utils.ts"]
  37bb944f_c341_9402_552c_323dacda08be --> 25b05299_f48f_bceb_01ca_1343d330a8f7
  5c46beaf_8b59_d2e3_def3_8af6daf1fccd["index.ts"]
  37bb944f_c341_9402_552c_323dacda08be --> 5c46beaf_8b59_d2e3_def3_8af6daf1fccd
  dd168f9e_7bec_1d6c_c69f_0fed98c81f3c["aggregate.ts"]
  37bb944f_c341_9402_552c_323dacda08be --> dd168f9e_7bec_1d6c_c69f_0fed98c81f3c
  be483a7f_d5d7_7a9b_9a13_44a4a6aafbbd["sql.ts"]
  37bb944f_c341_9402_552c_323dacda08be --> be483a7f_d5d7_7a9b_9a13_44a4a6aafbbd
  c9460fa2_b68e_584b_2be3_a4db38ea6f7c["index.ts"]
  37bb944f_c341_9402_552c_323dacda08be --> c9460fa2_b68e_584b_2be3_a4db38ea6f7c
  ecce3253_1e75_a87f_27b3_ca87e81a3024["utils.ts"]
  37bb944f_c341_9402_552c_323dacda08be --> ecce3253_1e75_a87f_27b3_ca87e81a3024
  style 37bb944f_c341_9402_552c_323dacda08be fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

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

const users = sqliteTable('names', {
	id: integer('id').primaryKey(),
	name: text('name'),
	managerId: integer('author_id'),
});

const posts = sqliteTable('posts', {
	id: integer('id').primaryKey(),
	authorId: integer('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 = 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)))
	.all();

Expect<
	Equal<
		{
			name: string | null;
			authorId: number | null;
			count1: number;
			totalCount: number;
		}[],
// ... (66 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/sqlite/subquery.ts (domain: DrizzleORM, directory: drizzle-orm/type-tests/sqlite).

Analyze Your Own Codebase

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

Try Supermodel Free