Home / File/ pg-common-cache.ts — drizzle-orm Source File

pg-common-cache.ts — drizzle-orm Source File

Architecture documentation for pg-common-cache.ts, a typescript file in the drizzle-orm codebase. 7 imports, 9 dependents.

File typescript DrizzleORM DatabaseDrivers 7 imports 9 dependents 1 functions 3 classes

Entity Profile

Dependency Diagram

graph LR
  7b6fdfe3_d9a8_26c3_430d_2261b1d7aadb["pg-common-cache.ts"]
  e9c5db23_dc8f_4a33_356a_8f8fbacc4a0e["dockerode"]
  7b6fdfe3_d9a8_26c3_430d_2261b1d7aadb --> e9c5db23_dc8f_4a33_356a_8f8fbacc4a0e
  690f7dfc_0aea_9ee8_d6e7_26bbb3689031["drizzle-orm"]
  7b6fdfe3_d9a8_26c3_430d_2261b1d7aadb --> 690f7dfc_0aea_9ee8_d6e7_26bbb3689031
  1887ab54_ea90_d248_26a5_4f0e40379db4["core"]
  7b6fdfe3_d9a8_26c3_430d_2261b1d7aadb --> 1887ab54_ea90_d248_26a5_4f0e40379db4
  d1b6cd91_8772_b4c9_66e1_10ab8d57e474["types"]
  7b6fdfe3_d9a8_26c3_430d_2261b1d7aadb --> d1b6cd91_8772_b4c9_66e1_10ab8d57e474
  53497908_16e7_977d_e97d_7414884a88a6["pg-core"]
  7b6fdfe3_d9a8_26c3_430d_2261b1d7aadb --> 53497908_16e7_977d_e97d_7414884a88a6
  1fec5f3c_6c99_322c_4189_0006f171f3de["keyv"]
  7b6fdfe3_d9a8_26c3_430d_2261b1d7aadb --> 1fec5f3c_6c99_322c_4189_0006f171f3de
  8d35eaf2_a542_cfd4_fa1a_fafca0f02686["vitest"]
  7b6fdfe3_d9a8_26c3_430d_2261b1d7aadb --> 8d35eaf2_a542_cfd4_fa1a_fafca0f02686
  6e2e482d_9a2a_072f_6dfa_c6293c2f4648["neon-http-batch.test.ts"]
  6e2e482d_9a2a_072f_6dfa_c6293c2f4648 --> 7b6fdfe3_d9a8_26c3_430d_2261b1d7aadb
  d27467f0_72cf_286d_a537_902fcaa2eddb["neon-http.test.ts"]
  d27467f0_72cf_286d_a537_902fcaa2eddb --> 7b6fdfe3_d9a8_26c3_430d_2261b1d7aadb
  a4af9c99_7399_27a8_3a5e_94b319250783["neon-serverless.test.ts"]
  a4af9c99_7399_27a8_3a5e_94b319250783 --> 7b6fdfe3_d9a8_26c3_430d_2261b1d7aadb
  32b18a19_4daf_0590_6caf_6ed6c0bfce80["node-postgres.test.ts"]
  32b18a19_4daf_0590_6caf_6ed6c0bfce80 --> 7b6fdfe3_d9a8_26c3_430d_2261b1d7aadb
  f1e8cfe5_698a_f227_ec0b_55d2af2a5373["pg-proxy.test.ts"]
  f1e8cfe5_698a_f227_ec0b_55d2af2a5373 --> 7b6fdfe3_d9a8_26c3_430d_2261b1d7aadb
  16fb6d5d_e8bb_e13a_97e7_c48de2589956["pglite.test.ts"]
  16fb6d5d_e8bb_e13a_97e7_c48de2589956 --> 7b6fdfe3_d9a8_26c3_430d_2261b1d7aadb
  8a70bea6_7c17_bc4e_0a1f_e2a09c3304fd["postgres-js.test.ts"]
  8a70bea6_7c17_bc4e_0a1f_e2a09c3304fd --> 7b6fdfe3_d9a8_26c3_430d_2261b1d7aadb
  style 7b6fdfe3_d9a8_26c3_430d_2261b1d7aadb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type Docker from 'dockerode';
import { eq, getTableName, is, sql, Table } from 'drizzle-orm';
import type { MutationOption } from 'drizzle-orm/cache/core';
import { Cache } from 'drizzle-orm/cache/core';
import type { CacheConfig } from 'drizzle-orm/cache/core/types';
import type { PgDatabase, PgQueryResultHKT } from 'drizzle-orm/pg-core';
import { alias, boolean, integer, jsonb, pgTable, serial, text, timestamp } from 'drizzle-orm/pg-core';
import Keyv from 'keyv';
import { afterAll, beforeEach, describe, expect, test, vi } from 'vitest';

// eslint-disable-next-line drizzle-internal/require-entity-kind
export class TestGlobalCache extends Cache {
	private globalTtl: number = 1000;
	private usedTablesPerKey: Record<string, string[]> = {};

	constructor(private kv: Keyv = new Keyv()) {
		super();
	}

	override strategy(): 'explicit' | 'all' {
		return 'all';
	}
	override async get(key: string, _tables: string[], _isTag: boolean): Promise<any[] | undefined> {
		const res = await this.kv.get(key) ?? undefined;
		return res;
	}
	override async put(
		key: string,
		response: any,
		tables: string[],
		isTag: boolean,
		config?: CacheConfig,
	): Promise<void> {
		await this.kv.set(key, response, config ? config.ex : this.globalTtl);
		for (const table of tables) {
			const keys = this.usedTablesPerKey[table];
			if (keys === undefined) {
				this.usedTablesPerKey[table] = [key];
			} else {
				keys.push(key);
			}
		}
	}
	override async onMutate(params: MutationOption): Promise<void> {
		const tagsArray = params.tags ? Array.isArray(params.tags) ? params.tags : [params.tags] : [];
		const tablesArray = params.tables ? Array.isArray(params.tables) ? params.tables : [params.tables] : [];

		const keysToDelete = new Set<string>();

		for (const table of tablesArray) {
			const tableName = is(table, Table) ? getTableName(table) : table as string;
			const keys = this.usedTablesPerKey[tableName] ?? [];
			for (const key of keys) keysToDelete.add(key);
		}

		if (keysToDelete.size > 0 || tagsArray.length > 0) {
			for (const tag of tagsArray) {
				await this.kv.delete(tag);
			}

// ... (341 more lines)

Domain

Subdomains

Functions

Types

Dependencies

  • core
  • dockerode
  • drizzle-orm
  • keyv
  • pg-core
  • types
  • vitest

Frequently Asked Questions

What does pg-common-cache.ts do?
pg-common-cache.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 pg-common-cache.ts?
pg-common-cache.ts defines 1 function(s): tests.
What does pg-common-cache.ts depend on?
pg-common-cache.ts imports 7 module(s): core, dockerode, drizzle-orm, keyv, pg-core, types, vitest.
What files import pg-common-cache.ts?
pg-common-cache.ts is imported by 9 file(s): neon-http-batch.test.ts, neon-http.test.ts, neon-serverless.test.ts, node-postgres.test.ts, pg-proxy.test.ts, pglite.test.ts, postgres-js.test.ts, vercel-pg.test.ts, and 1 more.
Where is pg-common-cache.ts in the architecture?
pg-common-cache.ts is located at integration-tests/tests/pg/pg-common-cache.ts (domain: DrizzleORM, subdomain: DatabaseDrivers, directory: integration-tests/tests/pg).

Analyze Your Own Codebase

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

Try Supermodel Free