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

postgres.ts — drizzle-orm Source File

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

File typescript DrizzleKit CLIWorkflow 5 imports 7 dependents 2 functions

Entity Profile

Dependency Diagram

graph LR
  aa34baa9_cce1_f1d8_4227_98c889d76b37["postgres.ts"]
  217e2cbd_4fb7_ceab_251c_5733ece08a8f["views.ts"]
  aa34baa9_cce1_f1d8_4227_98c889d76b37 --> 217e2cbd_4fb7_ceab_251c_5733ece08a8f
  b0ef3d06_896b_eefc_c410_dfb419673d70["error"]
  aa34baa9_cce1_f1d8_4227_98c889d76b37 --> b0ef3d06_896b_eefc_c410_dfb419673d70
  9135e6b6_37f7_c980_ee35_90f5531de5a4["common.ts"]
  aa34baa9_cce1_f1d8_4227_98c889d76b37 --> 9135e6b6_37f7_c980_ee35_90f5531de5a4
  b00190f0_9c7c_acbf_86f7_950ac8c79592["wrapParam"]
  aa34baa9_cce1_f1d8_4227_98c889d76b37 --> b00190f0_9c7c_acbf_86f7_950ac8c79592
  9d8cc145_835b_8147_2ea5_b7b5383ae775["zod"]
  aa34baa9_cce1_f1d8_4227_98c889d76b37 --> 9d8cc145_835b_8147_2ea5_b7b5383ae775
  e668bfef_9125_1ef0_2f94_a0f9605584bd["api.ts"]
  e668bfef_9125_1ef0_2f94_a0f9605584bd --> aa34baa9_cce1_f1d8_4227_98c889d76b37
  c2c22050_0d5c_404e_2b18_5934c728a89c["introspect.ts"]
  c2c22050_0d5c_404e_2b18_5934c728a89c --> aa34baa9_cce1_f1d8_4227_98c889d76b37
  6219550e_1686_ca7a_0d96_0838fb90e7cb["push.ts"]
  6219550e_1686_ca7a_0d96_0838fb90e7cb --> aa34baa9_cce1_f1d8_4227_98c889d76b37
  09e5bcf1_0f03_3dbd_fbdb_762440f28855["utils.ts"]
  09e5bcf1_0f03_3dbd_fbdb_762440f28855 --> aa34baa9_cce1_f1d8_4227_98c889d76b37
  4e02c2bb_54a8_1500_813e_2cafd1ad4f59["connections.ts"]
  4e02c2bb_54a8_1500_813e_2cafd1ad4f59 --> aa34baa9_cce1_f1d8_4227_98c889d76b37
  b30392fa_f107_a197_96c4_0d1a6ce594a2["studio.ts"]
  b30392fa_f107_a197_96c4_0d1a6ce594a2 --> aa34baa9_cce1_f1d8_4227_98c889d76b37
  82de12f8_a8ca_9d38_8da8_9ac945d81e01["studio.ts"]
  82de12f8_a8ca_9d38_8da8_9ac945d81e01 --> aa34baa9_cce1_f1d8_4227_98c889d76b37
  style aa34baa9_cce1_f1d8_4227_98c889d76b37 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { boolean, coerce, literal, object, string, TypeOf, undefined, union } from 'zod';
import { error } from '../views';
import { wrapParam } from './common';

export const postgresCredentials = union([
	object({
		driver: undefined(),
		host: string().min(1),
		port: coerce.number().min(1).optional(),
		user: string().min(1).optional(),
		password: string().min(1).optional(),
		database: string().min(1),
		ssl: union([
			literal('require'),
			literal('allow'),
			literal('prefer'),
			literal('verify-full'),
			boolean(),
			object({}).passthrough(),
		]).optional(),
	}).transform((o) => {
		delete o.driver;
		return o as Omit<typeof o, 'driver'>;
	}),
	object({
		driver: undefined(),
		url: string().min(1),
	}).transform<{ url: string }>((o) => {
		delete o.driver;
		return o;
	}),
	object({
		driver: literal('aws-data-api'),
		database: string().min(1),
		secretArn: string().min(1),
		resourceArn: string().min(1),
	}),
	object({
		driver: literal('pglite'),
		url: string().min(1),
	}),
]);

export type PostgresCredentials = TypeOf<typeof postgresCredentials>;

export const printConfigConnectionIssues = (
	options: Record<string, unknown>,
) => {
	if (options.driver === 'aws-data-api') {
		let text = `Please provide required params for AWS Data API driver:\n`;
		console.log(error(text));
		console.log(wrapParam('database', options.database));
		console.log(wrapParam('secretArn', options.secretArn, false, 'secret'));
		console.log(wrapParam('resourceArn', options.resourceArn, false, 'secret'));
		process.exit(1);
	}

	if ('url' in options) {
		let text = `Please provide required params for Postgres driver:\n`;
		console.log(error(text));
		console.log(wrapParam('url', options.url, false, 'url'));
		process.exit(1);
	}

	if ('host' in options || 'database' in options) {
		let text = `Please provide required params for Postgres driver:\n`;
		console.log(error(text));
		console.log(wrapParam('host', options.host));
		console.log(wrapParam('port', options.port, true));
		console.log(wrapParam('user', options.user, true));
		console.log(wrapParam('password', options.password, true, 'secret'));
		console.log(wrapParam('database', options.database));
		console.log(wrapParam('ssl', options.ssl, true));
		process.exit(1);
	}

	console.log(
		error(
			`Either connection "url" or "host", "database" are required for PostgreSQL database connection`,
		),
	);
	process.exit(1);
};

Domain

Subdomains

Frequently Asked Questions

What does postgres.ts do?
postgres.ts is a source file in the drizzle-orm codebase, written in typescript. It belongs to the DrizzleKit domain, CLIWorkflow subdomain.
What functions are defined in postgres.ts?
postgres.ts defines 2 function(s): postgresCredentials, printConfigConnectionIssues.
What does postgres.ts depend on?
postgres.ts imports 5 module(s): common.ts, error, views.ts, wrapParam, zod.
What files import postgres.ts?
postgres.ts is imported by 7 file(s): api.ts, connections.ts, introspect.ts, push.ts, studio.ts, studio.ts, utils.ts.
Where is postgres.ts in the architecture?
postgres.ts is located at drizzle-kit/src/cli/validations/postgres.ts (domain: DrizzleKit, subdomain: CLIWorkflow, directory: drizzle-kit/src/cli/validations).

Analyze Your Own Codebase

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

Try Supermodel Free